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&amp;mysql 日期操作小记

在时间比较查询的时候,int的效率明显更高。祥文见https://www.jb51.net/article/29767.htm 但是在做项目的时候或者直接在数据库查看数据的时候,明显这个...

Windows下PHP开发环境搭建教程(Apache+PHP+MySQL)

Windows下PHP开发环境搭建教程(Apache+PHP+MySQL)

由于换电脑或重装系统后常需要重新搭建PHP环境,此次简单记录一下Windows下搭建PHP环境的过程,具体步骤可以参照网上资料 准备工作: Windows下手工搭建PHP环境需要先下载相...

PHP中mysql_field_type()函数用法

本文实例讲述了PHP中mysql_field_type()函数用法。分享给大家供大家参考。具体如下: 定义和用法:mysql_field_type() 函数返回结果集中指定字段的类型,如...

php简单备份与还原MySql的方法

本文实例讲述了php简单备份与还原MySql的方法。分享给大家供大家参考,具体如下: 一、备份: <?php header ( "content-Type: text/...

mysql建立外键

建立外键的前提:本表的列必须与外键类型相同(外键必须是外表主键)。 外键作用: 使两张表形成关联,外键只能引用外表中的列的值! 指定主键关键字: f...