How connect and select data from mysql.

 

  These are following  steps   we  need to connect the  mysql database using node 


    1.  Create   a variable . 

    2.  Create  connection variable 

    3.  Select data from table 


 This  code  is  saved  in  mysqlselect.js  file  in   your folder .




 var mysql = require('mysql');


var con = mysql.createConnection({
  host: "localhost",
  user: "root",         
  password: "demopass",   
  database: "mkjhadatabase" 
});

con.connect(function(err) {
  if (err) throw err;
  con.query("SELECT * FROM  users"function (err, result, fields) {
    if (err) throw err;
    console.log(result);
  });
});






 Test   the   result  using node command 

               node   mysqlselect.js



How connect and select data from mysql.  How connect and  select data from mysql. Reviewed by Mukesh Jha on 5:27 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.