javascript - node.js & mysql - How to get the last inserted ID? -
db.query("insert `chat_entries`(`author`, `authorrank`, `receiver`, `timestamp`, `message`) values (" + db.escape(getusername(connection)) + ", " + getuserdata(getusername(connection), "rank") + ", '-', " + math.round(new date().gettime() / 1000) + ", '" + db.escape(messagedata.message) + "')", function(result, rows){ console.log(result.insertid); });
the console told me:
cannot read property 'insertid' of null
after had searched solution found page: https://github.com/mysqljs/mysql#getting-the-id-of-an-inserted-row
according documentation, must work. where's mistake? in advance.
you need replace
console.log(result.insertid);
with
console.log(rows.insertid);
since it's varibale you're passing callback function.
Comments
Post a Comment