Define multiple fields in prepared queries in NodeJS

I am using mysql library in Node

This is what I use instead of a prepared statement and works great:

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

However, this does not work for 2 unkowns:

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

The error message says: "undefined is not a function." What am I doing wrong?

+4
source share
1 answer

You need to define the values ​​in one array, for example:

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

All the necessary functions can be easily found here: https://github.com/felixge/node-mysql/#preparing-queries

+6
source

Source: https://habr.com/ru/post/1615877/


All Articles