mahdi pishguy mahdi pishguy - 7 months ago 27
MySQL Question

I get undefined when I try to get id of last updated row

The below MySQL command was tested on phpmyadmin and worked fine. The command doesn't have any problem. When I try to use it on Node.js I can't get result of the updated id and I get


function registerNewAccount(username, password, name, family, mobileNumber, callback) {

var query = "SET @update_id := 0; UPDATE users SET username = ?, password = ?, name= ?, family = ?, id = (SELECT @update_id := id) WHERE mobileNumber = ?; SELECT @update_id;";
connection.query(query, [username, password, name, family, mobileNumber] , function (err, results) {
if (err) return callback(false);


I'm trying to get the id of last updated row with this command. How can I fix that?


You need to create connection like this : var connection = mysql.createConnection({multipleStatements: true});