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

yipeiwu_com5年前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实现的mysqldb读写分离操作类示例

本文实例讲述了php实现的mysqldb读写分离操作类。分享给大家供大家参考,具体如下: /** * php MysqlDB 读写分离类 * --------------------...

PHP使用mysql_fetch_row查询获得数据行列表的方法

本文实例讲述了PHP使用mysql_fetch_row查询获得数据行列表的方法。分享给大家供大家参考。具体分析如下: 这里使用mysql_fetch_row从mysql数据库中查询数据,...

php mysql_list_dbs()函数用法示例

本文实例讲述了php mysql_list_dbs()函数用法。分享给大家供大家参考,具体如下: mysql_list_dbs()函数 定义:列出MySQL服务器中所有的数据库 $c...

PHP以mysqli方式连接类完整代码实例

本文所述的是一个在PHP中以mysqli方式连接数据库的一个数据库类实例,该数据库类是从一个PHP的CMS中整理出来的,可实现PHP连接数据库类,MySQLi版,兼容PHP4,对于有针对...

PHP操作MySQL的mysql_fetch_* 函数的常见用法教程

mysql_fetch_* 列函数 mysql_fetch_* 列函数的主要功能是从查询返回的结果集中取得相关的查询结果,主要包括: mysql_fetch_array():从结果...