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+mysqli预处理技术实现添加、修改及删除多条数据的方法

本文实例讲述了php+mysqli预处理技术实现添加、修改及删除多条数据的方法。分享给大家供大家参考。具体分析如下: 首先来说说为什么要有预处理(预编译)技术?举个例子:假设要向数据库添...

用mysql内存表来代替php session的类

复制代码 代码如下:<?php /** @Usage: use some other storage method(mysql or memcache) instead of ph...

php Mysql日期和时间函数集合

收集的比较全的Mysql日期和mysql时间函数 DATE_FORMAT(date,format)  根据format字符串格式化date值。下列修饰符可以被用在form...

PHP+Mysql+jQuery查询和列表框选择操作实例讲解

PHP+Mysql+jQuery查询和列表框选择操作实例讲解

本文讲解如何通过ajax查询mysql数据,并将返回的数据显示在待选列表中,再通过选择最终将选项加入到已选区,可以用在许多后台管理系统中。本文列表框的操作依赖jquery插件。 HTM...

DW中链接mysql数据库时,建立字符集中文出现乱码的解决方法

只是中文出现乱码时,在链接数据库后面,加上这一句 utf8的话 mysql_query("SET NAMES 'utf8'"); gbk的话 mysql_query("SET NAMES...