This article mainly introduces how to judge whether the update statement is successfully executed by php + MySQL. it can be implemented through the mysql_affected_rows method, if you need an update statement, you can refer to it as a common operation in PHP + MySQL. it is very important to judge whether the update statement is successfully executed. This article uses examples to demonstrate how php + MySQL can determine whether the update statement is successfully executed. Share it with you for your reference. The specific method is as follows:
Code 1:
$ Rs = MySQL_query ($ SQL); if (mysql_affected_rows () echo "SQL execution successful"; elseecho "SQL execution failed ";
Code 2:
<? Php/* connect to the database */mysql_pconnect ("localhost", "mysql_user", "mysql_passWord") or die ("cocould not connect ". mysql_error (); mysql_select_db ("mydb");/* Update record */mysql_query ("UPDATE mytable SET used = 1 WHERE id <10"); printf ("Updated records: % d \ n ", mysql_affected_rows (); mysql_query (" COMMIT ");?>
To observe the update execution, mysql_affected_rows () is required.
I believe this article has some reference value for everyone's PHP + MySQL program design.