I am a beginner for Node.js. Please help to fix this.
Without giving WHERE clause update is working fine. Below is the script without "WHERE" clause:
var post = {name: 'Amit', mobile:'123456'};
var query = connection.query('UPDATE contacts SET ? ', post , function(err, result) {});
console.log(query.sql);
Output:
Now I added 'WHERE' clause..getting error:
var post = {name: 'Amit', mobile:'123456'};
var condition = {id:4};
var query = connection.query('UPDATE contacts SET ? ',post,' WHERE '+ condition , function(err, result) {});
console.log(query.sql);
Output:
According to the api, your should write you query like this:
connection.query('UPDATE contacts SET Name = ?,Mobile=? WHERE yourCondition = ?', [post.name,post.mobile,condition], function(err, result) {})
try this ,it workd for me
connection.query('UPDATE nodeDB.USER SET USER_PASSWORD :Pass WHERE USER_NAME :Name',
{Name: 'max',Pass: '123'}, function(err, rows) {
});