php更新mysql后获取影响的行数发生异常解决方法

yipeiwu_com6年前Mysql基础
从manual上知道了mysql_affected_rows函数当UPDATE前后的数据一样时会返回异常值,

下面有个方便的解决办法,从官方munual上看到 bdobrica at gmail dot com 留言的:
As a solution to the problem pointed in the post reffering to mysql_affected_rows() returning 0 when you are making an update query and the fields are not modified although the query is valid, i'm posting the following function. It is very simple and based on a previous post.
复制代码 代码如下:

function mysql_modified_rows () {
$info_str = mysql_info();
$a_rows = mysql_affected_rows();
ereg("Rows matched: ([0-9]*)", $info_str, $r_matched);
return ($a_rows < 1)?($r_matched[1]?$r_matched[1]:0):$a_rows;
}

PS:因为这个小问题折腾了半天,感觉php真是太不清晰了

相关文章

php mysql操作mysql_connect连接数据库实例详解

mysql_connect介绍 php mysql_connect用于连接mysql服务器,该函数有多个参数,但我们一般只需要了解以下三个参数即可: mysql_connect(se...

PHP+Mysql日期时间如何转换(UNIX时间戳和格式化日期)

写过PHP+MySQL的程序员都知道有时间差,UNIX时间戳和格式化日期是我们常打交道的两个时间表示形式,Unix时间戳存储、处理方便,但是不直观,格式化日期直观,但是处理起来不如Uni...

apache2.2.4+mysql5.0.77+php5.2.8安装精简

1.安装Apache 将httpd-2.2.4.tar.gz拷贝至/usr/local/src目录中 tar -zxvf httpd-2.2.4.tar.gz cd httpd-2.2....

mysql_connect localhost和127.0.0.1的区别(网络层阐述)

connects.php 复制代码 代码如下: mysql_connect('127.0.0.1','root','zzzizzz1'); mysql_connect('localhos...

PHP使用PDO实现mysql防注入功能详解

本文实例讲述了PHP使用PDO实现mysql防注入功能。分享给大家供大家参考,具体如下: 1、什么是注入攻击 例如下例: 前端有个提交表格: <form action="t...