Reputation: 892
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
Upvotes: 1
Views: 786
Reputation: 382464
In order to have the program wait for your queries to be executed, replace
connection.destroy();
with
connection.end();
Upvotes: 2