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真是太不清晰了

相关文章

关于mysql字符集设置了character_set_client=binary 在gbk情况下会出现表描述是乱码的情况

mysql链接建立之后,通过如下方式设置编码: 复制代码 代码如下: mysql_query("SET character_set_connection=" . $GLOBALS['ch...

PHP 获取MySQL数据库里所有表的实现代码

复制代码 代码如下: function list_tables($database) { $rs = mysql_list_tables($database); $tables = ar...

php+mysqli使用预处理技术进行数据库查询的方法

本文实例讲述了php+mysqli使用预处理技术进行数据库查询的方法。分享给大家供大家参考。具体如下: 代码有些难度,需要基础知识比较扎实才能好理解,代码先放上来: 这里实现查询所有 i...

PHP开发者常犯的10个MySQL错误更正剖析

1.使用MyISAM而不是InnoDB   完全错误,反驳理由:   首先原文说MyISAM是默认使用的,而实际上到了MySQL 5.5.x,InnoDB已经成为了默认的表引擎。   另...

MySQL的FIND_IN_SET函数使用方法分享

很多时候我们在设计数据库时有这种情况,比如: 有个文章表里面有个type字段,他存储的是文章类型,有 1头条,2推荐,3热点,4图文 .....11,12,13等等 现在有篇文章他既是...