最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

得到一个MySQL请求的答案

运维笔记admin18浏览0评论

得到一个MySQL请求的答案

得到一个MySQL请求的答案

我编码一个网站实现条纹API。我使用的NodeJS和MySQL。我需要创建2个表保存多个信息。

我有一个表中的一个ID,并在第二个表中的AUTHID。我试图让链接2代表与那些ID,这样我就可以轻松地将它们链接在一起。因此,我创建了一个节省的第一个表的ID,并把它变成了2变量,但我不能设法保存它。

这里是我的代码:

        var sqlstripe = "SELECT id FROM authentification WHERE customerID = '" + customer.id +"'";
    console.log("getting ID from auth to put it in stripeID");
    var rowIDinDB = DB.query(sqlstripe, function (err, result) {
        if (err) throw err;
        console.log(result);
    });

    var sqlInsertstrip = "INSERT INTO stripeid (authID, customerID, subscriptionID, amount, date) VALUES ?";
    var valuesstripe = [
        [rowIDinDB, customer.id, subscription.id, subscription.amount, datenow]
    ];
    console.log('sending data to the DB for StripeID table');
    DB.query(sqlInsertstrip, [valuesstripe], function (err, result) {
        if (err) throw err;
        console.log(result);
    });

我保存在“sqlstripe”的要求,但是当我它张贴rowIDinDB下,我得到:错误:ER_TRUNCATED_WRONG_VALUE_FOR_FIELD:不正确的整数值:“[对象的对象]”列“AUTHID”第1行

AUTH ID是无符号SMALLINT,ID以及。

感谢您的帮助,如果你知道如何解决

回答如下:

注释是有点难以添加代码,所以把一个答复这里。既然你,你提到的未使用的承诺,你需要把你的代码中的回调。

免责声明,我没有测试它不知道你正在使用的包。但这个想法是rowIDinDB是不是你正在寻找的结果是,在结果的回调。

var sqlstripe =
  "SELECT id FROM authentification WHERE customerID = '" + customer.id + "'";
console.log("getting ID from auth to put it in stripeID");
DB.query(sqlstripe, function(err, result) {
  if (err) throw err;
  console.log(result);

  let rowIDinDB = result.rows; // ????? Attention, depends on your library, to USE the RIGHT properties

  var sqlInsertstrip =
    "INSERT INTO stripeid (authID, customerID, subscriptionID, amount, date) VALUES ?";
  var valuesstripe = [
    [rowIDinDB, customer.id, subscription.id, subscription.amount, datenow]
  ];
  console.log("sending data to the DB for StripeID table");
  DB.query(sqlInsertstrip, [valuesstripe], function(err, result) {
    if (err) throw err;
    console.log(result);
  });
});

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论