php更新mysql后获取影响的行数发生异常解决方法
发布于 2014-12-14 14:59:00 | 144 次阅读 | 评论: 0 | 来源: 网友投递
PHP开源脚本语言PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,入门门槛较低,易于学习,使用广泛,主要适用于Web开发领域。PHP的文件后缀名为php。
本文为大家讲解的是php更新mysql后获取影响的行数发生异常解决方法,感兴趣的同学参考下。
mysql_affected_rows函数当UPDATE前后的数据一样时会返回异常值
从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 base64编码后解码乱码的解决办法
PHP使用Alexa API获取网站的Alexa排名示例
php preg_match_all采集后数据处理的一点心得笔记(编码转换和正则匹配)
使用PHP实现Mysql读写分离的方法
php操作mysql执行数据库查询的一些常用函数操作汇总
php中mysql模块部分功能的简单封装(db基类)
在php和MySql中计算时间差的方法
PHP用mysql数据库存储session的方法
PHP更新中间关联表数据的两种方法
PHP与MYSQL中UTF8编码的中文排序实例