I am trying to do a statement in node using mysql package. I am trying to select from a table WHERE with a AND clause such as WHERE id = 1 AND course = 1 so far I've got as far as being able to SELECT but I'm getting an error, I can see the error though and it's that there is no AND when I am binding the id.
This is my current code.
let sql = 'SELECT * FROM users WHERE ?';
let values = {
id: 1,
course: 1
}
database.query(sql, values, (err, result) => {
}
This is the error I am getting...
SELECT * FROM users WHERE id = 1, course = 1
The query once it has been through node is missing the AND
Any help would be appreciated.
probably should look smth like this:
let sql = 'SELECT * FROM users WHERE id = ? AND course = ?';
database.query(sql, [1, 1], (err, result) => {
}
https://www.w3schools.com/nodejs/shownodejs_cmd.asp?filename=demo_db_where_placeholders
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With