nodejs mysql多个地方查询的地方
我一直在使用mysql的nodejs了一下,我似乎无法弄清楚如何使用查询与多个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);} });
感谢你并致以真诚的问候
我
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 });