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数据 dbclass类

复制代码 代码如下: class dbClass{ //开始数据库类 var $username; var $password; var $database; var $hostname...

小结下MySQL中文乱码,phpmyadmin乱码,php乱码 产生原因及其解决方法第1/3页

乱码产生原因  mysql字符编码是版本4.1引入的,支持多国语言,而且一些特性已经超过了其他的数据库系统。 我们可以在MySQL Command Line...

PHP递归写入MySQL实现无限级分类数据操作示例

本文实例讲述了PHP递归写入MySQL实现无限级分类数据操作。分享给大家供大家参考,具体如下: PHP递归写入MySQL无限级分类数据,表结构: CREATE TABLE `kepl...

PHP+mysql实现的三级联动菜单功能示例

本文实例讲述了PHP+mysql实现的三级联动菜单功能。分享给大家供大家参考,具体如下: 数据库mysql -- 数据库: `student` -- -- -------------...

mysql_connect localhost和127.0.0.1的区别(网络层阐述)

connects.php 复制代码 代码如下: mysql_connect('127.0.0.1','root','zzzizzz1'); mysql_connect('localhos...