php更新mysql后获取影响的行数发生异常解决方法

yipeiwu_com5年前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 Date/Time 类型

 由于曾经和他是同一个团队的,所以对于其我很熟悉他那“洁癖”的做法,对于他的很多的观点我也非常的赞同;但是有一件非常不理解的地方就是设计数据库的时候总是会回避使用 D...

PHP 使用MySQL管理Session的回调函数详解

复制代码 代码如下:<?php class MySession extends DBSQL {  /**   * __constr...

php和mysql中uft-8中文编码乱码的几种解决办法

PHP页面转UTF-8编码问题 1.在代码开始出加入一行: 复制代码 代码如下: header("Content-Type: text/html;charset=utf-8"); 2....

PHP mysqli事务操作常用方法分析

本文实例讲述了PHP mysqli事务操作常用方法。分享给大家供大家参考,具体如下: 1、 //打开(true)或关闭(false)本次数据库连接的自动命令提交事务模式 //参数如果...

php实现Mysql简易操作类

自己封装的Mysql简易操作类,已塞在Ben框架中,基于PDO来写的,代码风格上有些无厘头。。。 mysql.class.php <?php class mysql e...