如何从Node JS调用MySql存储过程

8

我希望从MySql node中调用存储过程:

我该如何调用?文档中写道:

You can call stored procedures from your queries as with any other mysql driver. If the stored procedure produces several result sets, they are exposed to you the same way as the results for multiple statement queries

我尝试在互联网上搜索,但得到的结果都很旧,不能再使用了。

我尝试过:

connection.query('procedure_name()', {84,Bhuwan}, function(err, result) {
    connection.destroy();
    if (err)
      throw err;
    callback(err, result);
});

但是我遇到了错误。

有人可以提供正确的语法吗?


什么是错误?另外,您是否尝试在查询字符串中添加“?”占位符,以包含要包含在查询中的[84,Bhuwan]值? - mscdex
也许这会有帮助?https://dev59.com/6Gkv5IYBdhLWcg3wgRCc - bencripps
1个回答

9

您需要使用“call”命令,并且如果您有要传递给查询的参数,则需要添加“?”标记。 请检查代码。

connection.query("call procedure_name(?,?)", [param1, param2], function (err, result) {
    if (err) {
        console.log("err:", err);
    } else {
        console.log("results:", result);
    }

});

7
如果你有一个OUT参数,会发生什么变化? - KingAndrew

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接