Environment
Node.js, MySQL (using
node-mysql library
connect)
At first
I could have one argument 'aaa'
or two arguments 'aaa' and 'bbb'
.
UPDATE user SET email = 'aaa' WHERE uid = 'xxx';
UPDATE user SET email = 'aaa', password = 'bbb' WHERE uid = 'xxx';
My problem
How could I use one query to overcome above cases? Like below ...
var sql = "UPDATE user SET email = ?, password = ? WHERE uid = ?;"
dbclient.query(sql, [email, password, uid], function (err, results) {
...
});
If two arguments were
defined
, variablesql
was :sql = "UPDATE user SET email = 'test@mail.com', password = 'abcd' WHERE uid = 1;";
If someone argument was
undefined
, variablesql
was :sql = "UPDATE user SET email = 'test@mail.com', password = password WHERE uid = 1;";
Aucun commentaire:
Enregistrer un commentaire