mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Mysql insert statement with functions

Open ashishkhanna opened this issue 10 years ago • 3 comments

Can you please help me to generate mentioned below insert statement in node syntax , I want to use md5 while inserting into database insert into user(user_id,username,password) values ( NULL,'f',md5('t')).

connection.query('INSERT INTO user SET ?', user, function(err, result) {}

ashishkhanna avatar Jul 11 '16 07:07 ashishkhanna

I recommend to set the query string before, something like:

var query = 'INSERT INTO user SET password=MD5(?), ?';
connection.query(query, ['supersecret', user], function (err, result) {});

where 'user' can be a json object without password key, to avoid error hope this can help you!

uribes78 avatar Sep 20 '16 19:09 uribes78

Hi @ashishkhanna , I hope @uribes78 was able to help you :) If you are looking for a library that provides advanced SQL constructing, a good one is the https://hiddentao.com/squel/ library.

dougwilson avatar Sep 21 '16 23:09 dougwilson

Thanks a ton for your help

Thanks & regards,

Ashish Khanna

On 22-Sep-2016 4:48 AM, "Douglas Wilson" [email protected] wrote:

Hi @ashishkhanna https://github.com/ashishkhanna , I hope @uribes78 https://github.com/uribes78 was able to help you :) If you are looking for a library that provides advanced SQL constructing, a good one is the https://hiddentao.com/squel/ library.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mysqljs/mysql/issues/1470#issuecomment-248771174, or mute the thread https://github.com/notifications/unsubscribe-auth/AEB1DFjAoZm7IfNuDKRbnkq5DzGjydEaks5qsbtGgaJpZM4JJGyl .

ashishkhanna avatar Sep 22 '16 03:09 ashishkhanna