如何将参数传入和传出到mysql存储过程并在nodejs代码中返回存储过程结果
问题描述:
connection.query("call vts_active_tagid('"+RFIDNumber+"','"+Latitude+"','"+Longitude+"','"+datetime+"','"+imeno+"',@passengers,@trip)");
此存储过程给出一个包含名字,电话号码和乘客ID的输出,以及如何在nodejs代码中获取这些值
this stored procedure gives one output which contains firstname,phone number and passengerid,how to get those values in the nodejs code
答
-
首先,将您的mysql设置为接受多条语句
First thing first, set your mysql to accept multiple statement
set mysql.createConnection({multipleStatements: true});
进行查询
query_str = "CALL sp_whatever(?,?,?,@output); select @output";
con.query(query_str, [param1, param2, param3], function(err,rows){
if(err) throw err;
console.log(rows);
});
query_str = "CALL sp_whatever(?,?,?,@output); select @output";
con.query(query_str, [param1, param2, param3], function(err,rows){
if(err) throw err;
console.log(rows);
});
输出:
[OkPacket {
fieldCount: 0,
affectedRows: 0,
insertId: 0,
serverStatus: 10,
warningCount: 0,
message: '',
protocol41: true,
changedRows: 0 },
[ RowDataPacket { '@output': -2 } ] ]