Query a connection object without parameters
suggest changePass the SQL string to connection.query. The callback is error-first: err, then rows, then fields. Each row contains the columns from that result. This is the mysql / mysql2 callback shape.
connection.query('SELECT name, email FROM users', function (err, rows, fields) {
if (err) throw err;
console.log('There are:', rows.length, 'users');
if (rows.length) {
console.log('First user name is:', rows[0].name);
}
});
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents