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真是太不清晰了

相关文章

MySQL的FIND_IN_SET函数使用方法分享

很多时候我们在设计数据库时有这种情况,比如: 有个文章表里面有个type字段,他存储的是文章类型,有 1头条,2推荐,3热点,4图文 .....11,12,13等等 现在有篇文章他既是...

PHP MYSQL实现登陆和模糊查询两大功能

PHP MYSQL实现登陆和模糊查询两大功能

本文使用的软件版本如下:PHP版本 5.5.12;MYSQL版本 5.6.17;Apache 2.4.9 用的wampserver 一、PHPMYSQL实现登陆 一共含有两个文件:log...

Windows下IIS6/Apache2.2.4+MySQL5.2+PHP5.2.1安装配置方法

03年的时候就看过一本php的书,那时还是php3,回首四年php的在web开的的前景真还是一片光明啊!三年不见的php在去看已到了php5了,现在算起我真正从写第一个php的WEB开始...

mysql时区问题

用convert_tz转换时区,你可以用      show   variables  ...

apache+php+mysql安装配置方法小结

apache+php+mysql安装配置方法小结

整个安装流程如下: 1,首先安装apache:我安装的版本是: httpd-2.2.16-win32-x86-openssl-0.9.8o.msi 网址:http://www.apach...