spare time to play nodejs when you encounter a bit of egg pain, in the use of MySQL module connection MySQL operation, want to update, DELETE statement, want to know exactly update, delete succeeded no
The way to do this directly in MySQL is to use Row_count (), which is followed by the SQL statement you execute. and Nodejs I/O is asynchronous so this creates a problem that is not very good at judging what SQL Execution Row_count () is. A cursory glance at the document does not describe the problem. The function nested to achieve the effect of synchronization, but did not find that in the execution of the SQL corresponding asynchronous functions in the parameters in the affectedrows field, tested, the product is the result of Row_count (). Instance: Copy code code 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 ': $, , ' state ': ' Failure ', & nbsp ' msg ': Msg, , ' data ': null , } return; } Res.send ({ , ' code ':, , ' state ': ' Success ', ' msg ': ' Updated ', ' data ': null }; });