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实现基于mysqli的Model基类完整实例

本文实例讲述了PHP实现基于mysqli的Model基类。分享给大家供大家参考,具体如下: DB.class.php <?php //数据库连接类 class...

MySQL修改密码方法总结

方法一  使用phpmyadmin,这是最简单的了,修改mysql库的user表,  不过别忘了使用PASSWORD函数。  方法二  使用mys...

用mysql内存表来代替php session的类

复制代码 代码如下:<?php /** @Usage: use some other storage method(mysql or memcache) instead of ph...

PHP5中使用mysqli的prepare操作数据库的介绍

php5中有了mysqli对prepare的支持,对于大访问量的网站是很有好处的,极大地降低了系统开销,而且保证了创建查询的稳定性和安全性。 PHP5.0后我们可以使用mysqli,my...

mysql+php分页类(已测)

复制代码 代码如下:<?php       /*      mysql...