Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在NodeJS中的准备好的查询中设置多个字段_Mysql_Node.js_Express_Prepared Statement - Fatal编程技术网

Mysql 在NodeJS中的准备好的查询中设置多个字段

Mysql 在NodeJS中的准备好的查询中设置多个字段,mysql,node.js,express,prepared-statement,Mysql,Node.js,Express,Prepared Statement,我正在节点中使用“mysql”库 这是我用来代替事先准备好的陈述的方法,效果很好: connection.query("update table set col1=? where col2=1",[val1],function(err,rows){ //connection.release(); if(!err) { //further code } }); 但是,这不适用于两种未知情况: con

我正在节点中使用“mysql”库

这是我用来代替事先准备好的陈述的方法,效果很好:

 connection.query("update table set col1=? where col2=1",[val1],function(err,rows){
        //connection.release();
        if(!err) {
          //further code
          }
        });
但是,这不适用于两种未知情况:

    connection.query("update table set col1=? where col2=?",[val1],[val2],function(err,rows){
        //connection.release();
        if(!err) {
          //further code
          }
        });

错误消息显示“未定义不是函数”。我做错了什么?

您需要在单个数组中定义值,如下所示:

connection.query("update table set col1=? where col2=?",[val1,val2],function(err,rows){
    //connection.release();
    if(!err) {
      //further code
      }
    });

所有必要的功能都可以在这里轻松找到:

非主题:您知道PostgreSQL的任何类似完整模块吗?别忘了标记答案。我想,您可以使用类似的东西。我的两个更新值中有逗号(,),这会搞乱查询。我该怎么做才能摆脱它?你确定你正在使用我提供的功能吗?库应将值转义为。