In mysql, row_count () is used to directly make such a judgment. This statement must be followed by the SQL statement you run. node. js's I/o operations are asynchronous, which leads to a problem. It is not good to judge which SQL statement row_count () is executed. after a rough glance at the document, the document does not describe the problem. if you want to implement the synchronization through function nesting, you have no intention of finding that the affectedRows field is included in the parameters of the asynchronous function corresponding to SQL Execution. After testing, this is the result of row_count.
Instance:Copy codeThe Code is as follows:
Var cmd = 'Update users set' + field + '=' + value + 'where id = '+ userid;
Console. log (cmd );
Db. query (cmd, function (err, rows, fields ){
Var affectedRows = rows. affectedRows;
If (err | affectedRows ){
Var msg = 'update' + field + 'error ';
Logger. error (msg );
Res. send ({
'Code': 500,
'State': 'failed ',
'Msg ': msg,
'Data': null
});
Return;
}
Res. send ({
'Code': 200,
'State': 'success ',
'Msg ': 'updated ',
'Data': null
});
});