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数据表的字段名称和详细信息的方法

首先我们需要了解下查询MySQL数据库/表相关信息的SQL语句: 复制代码 代码如下: SHOW DATABASES      ...

PHP读MYSQL中文乱码的解决方法

打算切换某个网站的主机,没想到遇到Php和Mysql中文乱码的问题。   以前的国外主机用的Mysql是4.x系列的,感觉还比较好,都无论GBK和UTF-8都没有乱码,没想到新的主机的M...

PHP+MySql+jQuery实现的"顶"和"踩"投票功能

本文实例为大家分享了基于PHP+jQuery+MySql实现红蓝(顶踩)投票代码,供大家参考,具体内容如下 数据库操作: CREATE TABLE IF NOT EXISTS `vo...

How do I change MySQL timezone?

However, there are ways for you to get results t...

MySQL 日期时间函数常用总结

MySQL 日期时间函数常用总结

 获得当前日期+时间(date + time)1.1    函数:now()  相关函数:current...