Return the query when an error occurs

suggest change

You can attach the SQL that ran to the err object. connection is a connection from the mysql package. connection.query returns the query object, and sql is the statement after placeholders are filled in.

var q = connection.query('SELECT `name` FROM `pokedex` WHERE `id` = ?', [25], function (err, result) {
  if (err) {
    // Table 'test.pokedex' doesn't exist
    err.query = q.sql; // SELECT `name` FROM `pokedex` WHERE `id` = 25
    callback(err);
  } else {
    callback(null, result);
  }
});

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents