PHP+MySQL method to determine whether update statement is executed successfully, mysqlupdate_PHP tutorial

WBOY
Release: 2016-07-13 10:19:57
Original
1259 people have browsed it

php+MySQL method to determine whether the update statement is executed successfully, mysqlupdate

The update statement is a commonly used operation in PHP+MySQL. Determining whether the update statement is executed successfully is a very important step. This article uses an example to demonstrate the method of php+MySQL to determine whether the update statement is executed successfully. Share it with everyone for your reference. The specific method is as follows:

Code 1:

$rs=MySQL_query($sql);
if(mysql_affected_rows())
echo "sql执行成功";
else
echo "sql执行失败";

Copy after login

Code 2:

<&#63;php
  /* 连接数据库 */
  mysql_pconnect("localhost", "mysql_user", "mysql_passWord") or die ("Could not connect" . mysql_error());
  mysql_select_db("mydb");
  /* Update 记录 */
  mysql_query("UPDATE mytable SET used=1 WHERE id < 10");
  printf ("Updated records: %d\n", mysql_affected_rows());
  mysql_query("COMMIT");
&#63;> 
Copy after login

To observe the execution of update, mysql_affected_rows() is required.

I believe that what is described in this article has certain reference value for everyone’s PHP+MySQL programming.

php determines whether the mysql statement is successfully executed

if(false!==mysql_query($sql)){ echo 'Success! ';}
This is enough to judge! If something goes wrong, you may have written the wrong code in front of you. Please post it and have a look! You said insert returns false. I guess you have executed mysql_query before and then used it to judge?

How to judge that update has been successfully executed in php mysql? 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: Du Niang

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/871096.htmlTechArticlephp+MySQL method to determine whether the update statement is executed successfully. The mysqlupdate update statement is a commonly used operation in PHP+MySQL. Determining whether the update statement is executed successfully is a very important link...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!