gpt4 book ai didi

mysql - mysql的where子句 Node 没有返回结果集?

转载 作者:行者123 更新时间:2023-11-29 10:37:44 25 4
gpt4 key购买 nike

我正在尝试通过传递 token 号来搜索 mysql 数据库,并且我想从数据库返回与该 token 附加的 id。我已经尝试过,但我看不到任何结果集,而且我对我做错了什么一无所知。 这是我到目前为止所尝试过的。

checkifuniquenumberexists:function(num){
con.connect(function (err) {
if (err) throw err;
console.log("Connected!");
var post = {"token": num};
var query = con.query('select id from uniquereviewtoken where token in (?)', post, function (err, result,fields) {
// Neat!
//console.log(query);
console.log("error", err);
console.log("result", result.length);
console.log("fields",fields);
return result;


});

});

mysql语法有问题吗?

这就是我在日志中得到的内容

1|service  | undefined
1|service | Connected!
1|service | error null
1|service | result 0
1|service | fields [ FieldPacket {
1|service | catalog: 'def',
1|service | db: 'review',
1|service | table: 'uniquereviewtoken',
1|service | orgTable: 'uniquereviewtoken',
1|service | name: 'id',
1|service | orgName: 'id',
1|service | charsetNr: 63,
1|service | length: 50,
1|service | type: 3,
1|service | flags: 16899,
1|service | decimals: 0,
1|service | default: undefined,
1|service | zeroFill: false,
1|service | protocol41: true },
1|service | FieldPacket {
1|service | catalog: 'def',
1|service | db: 'review',
1|service | table: 'uniquereviewtoken',
1|service | orgTable: 'uniquereviewtoken',
1|service | name: 'token',
1|service | orgName: 'token',
1|service | charsetNr: 33,
1|service | length: 3000,
1|service | type: 253,
1|service | flags: 4097,
1|service | decimals: 0,
1|service | default: undefined,
1|service | zeroFill: false,
1|service | protocol41: true } ]

最佳答案

您不需要 post 对象。引用:https://www.npmjs.com/package/mysql#preparing-queries

checkifuniquenumberexists: function(num) {
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var query = con.query('select id from uniquereviewtoken where token in (?)', num, function(err, result, fields) {
// Neat!
//console.log(query);
console.log("error", err);
console.log("result", result.length);
console.log("fields", fields);
return result;


});

});

关于mysql - mysql的where子句 Node 没有返回结果集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46118486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com