Home >Web Front-end >JS Tutorial >Nodejs uses the mysql module to obtain the number of rows affected by updates and deletions_javascript skills
The way to directly make such a judgment in mysql is to use row_count(). This statement must follow the sql statement you execute. The I/O of Nodejs is asynchronous, so this creates a problem, which is not easy to judge. Row_count() is the result of which SQL statement is executed. After a cursory glance at the document, this issue is not described in the document. I originally wanted to nest functions to achieve synchronization effects, but accidentally found that in the asynchronous function corresponding to the SQL execution There is an affectedRows field in the parameters. After testing, this is the result of row_count().
Example:
res.send({
'code': 500,
'state': 'failure',
'msg': msg,
'data': null
}) ;
return;
}
res.send({
'code': 200,
'state': 'success',
'msg': 'updated',
'data': null
});
});