简体   繁体   中英

unable to connect to database in nodejs?

I am reading this and tried to connect to MYSQL database using node js.Here is my program

var mysql =  require('mysql');
var connection =  mysql.createConnection({
host : "localhost",
    User : "root",
password: ""
 });
connection.connect();
connection.query("use test");
var strQuery = "select * from chat";    

connection.query( strQuery, function(err, rows){
if(err) {
    throw err;
}else{
    console.log( rows );
}
 })
  connection.destroy( );

I an not getting any error but also unable to get any output

In order to have the program wait for your queries to be executed, replace

connection.destroy();

with

connection.end();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM