Retrieve last inserted id with Mysql

https://github.com/mysqljs/mysql#getting-the-id-of-an-inserted-row
describes the solution perfectly well:

connection.query('INSERT INTO posts SET ?', {title: 'test'}, function(err, result, fields) {
  if (err) throw err;

  console.log(result.insertId);
});

Leave a Comment