2017-05-16 178 views
0

我想檢查一個NodeJS查詢,其中用戶的ID是例如1和他的private_number是25,下面的代碼不起作用。查詢檢查在哪裏

query('SELECT * FROM `users` WHERE `user` = '+pool.escape(user)+', `private_number` ='+pool.escape(number), function(err, row) { //get if the player has a query with the same code 

}); 

這是否有可能嗎?

回答

1

您可以使用模板字符串

query(`SELECT * FROM users WHERE user = ${pool.escape(user)} AND 
private_number = ${pool.escape(number)}`), function(err, row) { 
}) 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

附:當你有WHERE條款,你需要用邏輯運算符「連接」他們像ANDOR

+0

那麼這將工作的多個條件.. 'SELECT * FROM'users' WHERE'user' =「+ pool.escape(用戶)+'AND'private_number' ='+ pool.escape(number)'或不是嗎? –