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入门教程之PHP操作MySQL的方法分析

PHP入门教程之PHP操作MySQL的方法分析

本文实例讲述了PHP操作MySQL的方法。分享给大家供大家参考,具体如下: 设置Zend 软件所有 UTF-8 编码 设置单个项目 UTF-8 的编码 Demo1.php <...

PHP+MySQL 手工注入语句大全 推荐

暴字段长度 Order by num/* 匹配字段 and 1=1 union select 1,2,3,4,5…….n/* 暴字段位置 and 1=2 union select 1,2...

解决了Ajax、MySQL 和 Zend Framework 的乱码问题

问题: 在 Google Map 上用 Ajax 以 get 方式向服务器传递数据时,服务器端显示为 url 乱码, Zend Framework 向 MySQL 存储数据为乱码,但是提...

mysql 搜索之简单应用

如何在MySQL中获得更好的全文搜索结果   作者: Techrepublic.com.com  2006-04-03 11:14:53...

php更新mysql后获取改变行数的方法

本文实例讲述了php更新mysql后获取改变行数的方法。分享给大家供大家参考。具体分析如下: 一个php更新mysql后获取改变的行数,在php中提供mysql函数来获取最后执行查询所影...