Php+mysql determines whether the UPDATE statement performs a successful method, Mysqlupdate
The UPDATE statement is a common operation in Php+mysql, and it is very important to determine whether the UPDATE statement is executed successfully. This article shows an example of how php+mysql can determine if the UPDATE statement is successful. Share it for everyone's reference. Here's how:
Code One:
$rs =mysql_query ($sql), if (Mysql_affected_rows ()) echo "SQL execution succeeded"; Elseecho "SQL execution failed";
Code two:
<?php/ * Connect to 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 ());
It is necessary to observe the implementation of update Mysql_affected_rows ().
It is believed that this article has certain reference value for the PHP+MYSQL program design of everyone.
PHP determines if MySQL statement is executed successfully
if (False!==mysql_query ($sql)) {echo ' succeeds! ';}
That's enough judgment! If there is an error, you may have the wrong code in front of you, please post it! You say insert returns FALSE, I guess you have executed the mysql_query before, and then take it to judge?
PHP MySQL How to determine the success of the update has been implemented, give a specific example?
........... 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";
}
Reference: Mother degree
http://www.bkjia.com/PHPjc/871096.html www.bkjia.com true http://www.bkjia.com/PHPjc/871096.html techarticle Php+mysql to determine whether the UPDATE statement performs a successful method, the Mysqlupdate UPDATE statement is a common operation in Php+mysql, and it is important to determine if the UPDATE statement is executed successfully.