use*_*779 5 mysql prepared-statement node.js express
我在Node中使用'mysql'库
这是我使用而不是准备好的声明,并且工作得很好:
connection.query("update table set col1=? where col2=1",[val1],function(err,rows){
//connection.release();
if(!err) {
//further code
}
});
Run Code Online (Sandbox Code Playgroud)
但是,这不适用于2个unkowns:
connection.query("update table set col1=? where col2=?",[val1],[val2],function(err,rows){
//connection.release();
if(!err) {
//further code
}
});
Run Code Online (Sandbox Code Playgroud)
错误消息显示"undefined不是函数".我究竟做错了什么?
您需要在单个数组中定义值,如下所示:
connection.query("update table set col1=? where col2=?",[val1,val2],function(err,rows){
//connection.release();
if(!err) {
//further code
}
});
Run Code Online (Sandbox Code Playgroud)
所有必要的功能都可以在这里轻松找到:https://github.com/felixge/node-mysql/#preparing-queries
| 归档时间: |
|
| 查看次数: |
3070 次 |
| 最近记录: |