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数据库整库导出生成sql文件的具体实现

由网上搜到,有更改。 文件名:db_backup.php 源代码如下: 复制代码 代码如下: <?php ini_set("max_execution_time", "180");...

MySql 按时间段查询数据方法(实例说明)

时间格式为2008-06-16 查询出当天数据: SELECT * FROM `table` WHERE date(时间字段) = curdate(); 查询出当月字段: SELECT...

php利用scws实现mysql全文搜索功能的方法

本文实例讲述了php利用scws实现mysql全文搜索功能的方法。分享给大家供大家参考。具体方法如下: scws这样的中文分词插件比较不错,简单的学习了一下,它包涵一些专有名称、人名、地...

php mysql_list_dbs()函数用法示例

本文实例讲述了php mysql_list_dbs()函数用法。分享给大家供大家参考,具体如下: mysql_list_dbs()函数 定义:列出MySQL服务器中所有的数据库 $c...

PHP把MSSQL数据导入到MYSQL的方法

本文实例讲述了PHP把MSSQL数据导入到MYSQL的方法。分享给大家供大家参考。具体分析如下: 最近需要把一个以前的asp网站转换成php的,但php是与mysql而我的asp与mss...