0

I have been using felixge/node-mysql with NodeJS to connect MySQL !

Following query not executing and not throwing any error also.

var mysql = require('mysql');

client.query('USE userrecorddetails');


client.query(
  'select count(1) as cnt as userstatus where id = 2353',
  function (err, results, fields) {
    if (err) {
      throw err;
    }
})

Note : the above query have zero records for that id 2353.

If any record is available, then i can able to get the output from the above query.

Please any help on this.

2
  • 1
    do yo mean that callback function is not called at all? Commented Oct 12, 2011 at 10:40
  • Correct! The callback function is not called! Commented Oct 12, 2011 at 11:01

1 Answer 1

2

I can't confirm your problem 1) original query contains errors 2) output from following example (no records with id=2352)

var client = require('mysql').createClient();
client.query('USE test');

client.query(
  //'select count(1) as cnt as userstatus where id = 2353',
  'select count(1) as cnt from userstatus where id = 2353',
  function (err, results, fields) {
    if (err) {
      console.log(err);
      throw err;
    }
    console.log(results, fields);
})

is

[ { cnt: 0 } ] { cnt: 
   { length: 25,
     received: 25,
     number: 2,
     type: 4,
     catalog: 'def',
     name: 'cnt',
     charsetNumber: 63,
     fieldLength: 21,
     fieldType: 8,
     flags: 129,
     decimals: 0 } }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. The query that i was posted is wrong. But in my code it is correct. Problem i was found that i am using 'client.end();' after the query. It is terminating mysql connection and does not go inside to the callback function.

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.