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中数据库连接方式pdo和mysqli对比分析

1)总的比较   PDO MySQLi 数据库支持 12种不同的...

PHP读取ACCESS数据到MYSQL的代码

复制代码 代码如下: <?php header('ontent-Type:text/html;charset=GB2312');//避免输出乱码 $dbhost ="localho...

PHP中mysqli_affected_rows作用行数返回值分析

本文实例分析了PHP中mysqli_affected_rows作用行数返回值。分享给大家供大家参考。具体分析如下: mysqli中关于update操作影响的行数可以有两种返回形式: 1....

PHP+MySQL实现模糊查询员工信息功能示例

PHP+MySQL实现模糊查询员工信息功能示例

本文实例讲述了PHP+MySQL实现模糊查询员工信息功能。分享给大家供大家参考,具体如下: 一、代码 注意两点: 1、用Notepad+编辑时,格式选择:【编码字符集】->【中文】...

mysql_escape_string()函数用法分析

本文实例讲述了mysql_escape_string()函数用法。分享给大家供大家参考,具体如下: 使用 mysql_escape_string() 对查询中有疑问的数据进行编码: 有...