如何将参数传入和传出到mysql存储过程并在nodejs代码中返回存储过程结果 [英] how to pass in and out parameters to a mysql stored procedure and return the stored procedure result in the nodejs code

查看:432
本文介绍了如何将参数传入和传出到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

推荐答案

  1. 首先,将您的mysql设置为接受多条语句

  1. 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 } ] ]

这篇关于如何将参数传入和传出到mysql存储过程并在nodejs代码中返回存储过程结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆