2014-09-29 80 views
3

我想打电话从MySql node存储过程调用MySql的程序?该文件说:如何从节点JS

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); 
}); 

但我得到的错误。

任何人都可以提供适当的语法吗?

+0

什么是错误?您是否也尝试在查询字符串中为查询中包含的[[84,Bhuwan]]值添加'?'占位符? – mscdex 2014-09-29 00:08:50

+0

也许这会帮助吗? http://stackoverflow.com/questions/10546956/is-there-a-driver-for-mysql-on-nodejs-that-supports-stored-procedures – bencripps 2014-09-29 00:37:38

回答

0

你必须使用'call'命令,如果你有参数传递给查询,你需要添加'?'分数。检查代码。

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

});