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实现简单的增删改查功能

列表代码 <?php $con = mysql_connect("localhost:3306","root",""); if (!$con) { d...

PHP 和 MySQL 开发的 8 个技巧

1. PHP 中数组的使用   在操作数据库时,使用关联数组(associatively-indexed arrays)十分有帮助,下面...

PHP数据库操作之基于Mysqli的数据库操作类库

此类库简单、易用,便于你自己修改和对功能的改善,能解决大部分 PHP 项目中执行的 SQL 操作。 初步工作 首先,请大家下载这个类库 M.class.php 再下载一个 My...

浅谈php中mysql与mysqli的区别分析

首先两个函数都是用来处理DB 的。首先, mysqli 连接是永久连接,而mysql是非永久连接。什么意思呢? mysql连接每当第二次使用的时候,都会重新打开一个新的进程,而mysql...

php实现带读写分离功能的MySQL类完整实例

本文实例讲述了php实现带读写分离功能的MySQL类。分享给大家供大家参考,具体如下: 概述: 1. 根据sql语句判断是连接读库还是写库 2. 链式调用$this->where(...