开发者

NodeJS Mysql count query for record check

开发者 https://www.devze.com 2023-04-12 16:32 出处:网络
I have been using felixge/node-mysql with NodeJS to connect MySQL ! Following query not executing and not throwing any error also.

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.


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 } }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号