The UPDATE statement is a common operation in Php+mysql, and it is very important to judge whether the update statement is successful or not. This article shows an example of how Php+mysql determines whether an UPDATE statement succeeds. Share for everyone to use for reference. The specific methods are as follows:
Code One:
$rs =mysql_query ($sql);
if (Mysql_affected_rows ())
echo "SQL execution succeeded";
else
echo "SQL execution failed";
Code two:
<?php/
* Connection Database
/mysql_pconnect ("localhost", "Mysql_user", "Mysql_password") or Die ("could not connect". My Sql_error ());
mysql_select_db ("MyDB");
/* Update record *
/mysql_query ("Update mytable SET used=1 WHERE ID <");
printf ("Updated Records:%d\n", mysql_affected_rows ());
mysql_query ("COMMIT");
? >
It is necessary to observe the implementation of update Mysql_affected_rows ().
It is believed that this article has certain reference value to the PHP+MYSQL program design of everybody.