find number of rows in returned mysql result (nodejs)

If it’s a select query, just take the length of the returned array.

connection.query(sql, [var1,var2], function(err, results) {
    numRows = results.length;
});

If it’s an update/delete query, the returned dictionary will have an affectedRows variable.

connection.query(sql, [var1,var2], function(err, result) {
    numRows = result.affectedRows;
});

Leave a Comment