1

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

7
  • @Quentin I have changed quotes but I am not getting any error but also not getting output as well Commented May 6, 2014 at 10:11
  • 1
    I voted too fast to close, there is another blocking problem. Commented May 6, 2014 at 10:16
  • @dystroy what should I do now? Commented May 6, 2014 at 10:19
  • 1
    Does it work with end() ? Commented May 6, 2014 at 10:24
  • 1
    Use rows[0].chat_name Commented May 6, 2014 at 10:36

1 Answer 1

2

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

connection.destroy();

with

connection.end();
Sign up to request clarification or add additional context in comments.

5 Comments

I have used standard quotes but now I am not getting output
Well. Change your standard and use the same quotes as other developers.
I am not getting any error but also not getting output as well
but it is giving output as [ { chat_name: 'John' } ].Could you tell me how to get just john from here
@Fresher try console.log( rows[0].chat_name );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.