Return the query when an error occurs
suggest changeYou 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);
}
});
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents