【问题标题】:How to get the answer of a mysql request and stock it?如何获得 mysql 请求的答案并存储它?
【发布时间】:2019-02-06 13:24:04
【问题描述】:

我正在构建一个服务器,我想知道一个密钥是否在我的 sql DB 中。 我想知道是否可以只获取sql请求的值还是需要解析?

function checkKey(key) {
   var sqlcheck = "SELECT customerID from authentification where discord_key = 
?";
console.log("in function");
DB.query(sqlcheck, [key], function (err, result) {
   if (err) throw err;
    console.log(result);
   });
}

这就是我得到的:

RowDataPacket { customerID: 'cus_ET5gXP7p7Tafmf' }

但我只想得到:

cus_ET5gXP7p7Tafmf

感谢您的帮助!

【问题讨论】:

  • console.log(result.customerID) 可能会成功。
  • 如果我这样做,我会得到“未定义”

标签: mysql sql node.js


【解决方案1】:

一般

result[0].customerID

但是在你的例子中它看起来像

result.customerID

【讨论】:

  • 我在使用 result.customerID 时得到“未定义”
  • result[0].customerID怎么样
  • 请使用console.log(JSON.Stringify(result)); 并在您的问题中提供结果
  • TypeError: JSON.Stringify 不是函数哦,它适用于结果 [0]!非常感谢!
  • 是的,我会找到更快的工作。但我还有其他需要迭代的东西抛出了 sql 答案,所以它是为了别的东西。非常感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-25
  • 1970-01-01
  • 2012-10-02
  • 1970-01-01
相关资源
最近更新 更多