Home  >  Article  >  Backend Development  >  php+MySQL判断update语句是否执行成功的方法_php技巧

php+MySQL判断update语句是否执行成功的方法_php技巧

WBOY
WBOYOriginal
2016-05-16 20:36:451259browse

update语句是PHP+MySQL中常用的操作,判断update语句是否执行成功是其中非常重要的一个环节。本文就以实例展示了php+MySQL判断update语句是否执行成功的方法。分享给大家供大家参考之用。具体方法如下:

代码一:

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

代码二:

<?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");
?> 

想观察update的执行情况mysql_affected_rows()是必需的。

相信本文所述对大家的PHP+MySQL程序设计有一定的借鉴价值。

Statement:
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