nodejs mysql multiple where查询的

nodejs mysql multiple where查询的

问题描述:

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

SELECT * FROM user_information其中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);} 
    }); 

谢谢你和问候

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 
    }); 
+0

哇哦谢谢!这帮了我很多! –

+0

欢迎!乐于帮助(: – num8er