Php + MySQL to determine whether the update statement is successfully executed, mysqlupdate
The update statement is 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.
Php checks whether mysql statements are successfully executed
If (false! = Mysql_query ($ SQL) {echo 'success! ';}
This judgment is sufficient! If the error occurs, you may have written an error in the previous Code. Please post it and see it! If you say "insert" returns false, I guess you have already executed mysql_query and then used it for judgment?
In php mysql, how does one determine that update has been successfully executed?
.......... Connect to the database .........
$ SQL = "update tb_user set name = 'sun' where id = 1 ";
$ Flag = mysql_query ($ SQL );
If ($ flag)
{
Echo 1;
}
Else
{
Echo "Update error ";
}
References: du Niang