nodejs mysql multiple where query's

时间:2017-04-23 20:09:40

标签: mysql node.js

我一直在使用nodejs中的mysql,我似乎无法弄清楚如何将查询与多个where语句一起使用。 像:

SELECT * FROM user_information WHERE a = a或b = b

现在我将此作为我的代码:

    connection.query("SELECT * FROM user_information WHERE username=" + registerarray[1] + " OR email=" + registerarray[3],function(err, results){
            if (err){console.error(err);}
    });

谢谢你,以及最好的问候

1 个答案:

答案 0 :(得分:1)

results是来自mysql的响应行。

让我们简化部分:

const 
  q = "SELECT * FROM user_information WHERE username=? OR email=?", // You can use placeholders like ? marks 
  args = [registerarray[1], registerarray[3]]; // array of values that will be set to placeholders (will be escaped for security)
connection
  .query(
    q, // our query
    args,  // placeholder values
    (err, records) => { // query response scope begins here
      if (err) {
        console.error(err);
      }

      console.log('THIS IS RESULT OF QUERY EXECUTION:');
      console.log(records); // this is result, already fetched array
    });