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数据库的类

本文实例讲述了php简单操作mysql数据库的类。分享给大家供大家参考。具体如下: <?php /** * Database class * * @version...

php mysqli查询语句返回值类型实例分析

本文实例分析了php mysqli查询语句返回值类型。分享给大家供大家参考,具体如下: <?php $link = new mysqli('localhost', 'r...

php+mysqli使用预处理技术进行数据库查询的方法

本文实例讲述了php+mysqli使用预处理技术进行数据库查询的方法。分享给大家供大家参考。具体如下: 代码有些难度,需要基础知识比较扎实才能好理解,代码先放上来: 这里实现查询所有 i...

mysql_fetch_assoc和mysql_fetch_row的功能加起来就是mysql_fetch_array

mysql_fetch_assoc只能用字段,就像mysql_fetch_array($result, MYSQL_ASSOC)结果一样。 mysql_fetch_row&nb...

PHP mysqli_free_result()与mysqli_fetch_array()函数详解

PHP mysqli_free_result()与mysqli_fetch_array()函数 mysql_free_result() 仅需要在考虑到返回很大的结果集时会占用多少内存时调...