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数据到csv文件的方法

本文实例讲述了php使用指定编码导出mysql数据到csv文件的方法。分享给大家供大家参考。具体实现方法如下: <?php /* * PHP code to expo...

php判断输入不超过mysql的varchar字段的长度范围

但是如果在utf-8编码下,一个汉字是占3个字符长度的,比如字符串$str=”你好啊!!”; 如果你用strlen函数来判断,长度是11,正好超过了varchar的长度,但实际上确不是这...

PHP7.0连接DB操作实例分析【基于mysqli】

PHP7.0连接DB操作实例分析【基于mysqli】

本文实例讲述了PHP7.0连接DB操作。分享给大家供大家参考,具体如下: PHP <?php //连接数据库 $link = mysqli_connect('local...

PHP开发环境配置(MySQL数据库安装图文教程)

PHP开发环境配置(MySQL数据库安装图文教程)

一、 MySQL的安装 运行MYSQL安装程序(mysql-essential-5.1.40-win32.msi)   选择安装类型为Custom   点选Cha...

PHP读取ACCESS数据到MYSQL的代码

复制代码 代码如下: <?php header('ontent-Type:text/html;charset=GB2312');//避免输出乱码 $dbhost ="localho...