Home > Backend Development > PHP Tutorial > Solution to exception when obtaining the number of affected rows after PHP updates mysql_PHP Tutorial

Solution to exception when obtaining the number of affected rows after PHP updates mysql_PHP Tutorial

WBOY
Release: 2016-07-21 15:12:25
Original
1281 people have browsed it

From the manual, I know that the mysql_affected_rows function will return an abnormal value when the data before and after UPDATE are the same.

There is a convenient solution below. From the official munual, I saw the message from 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.

Copy code The code is as follows:

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: After struggling with this small problem for a long time, I feel that php is really unclear.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326696.htmlTechArticleI know from the manual that the mysql_affected_rows function will return an abnormal value when the data before and after UPDATE are the same. Here is a convenient method Solution, see bdobrica at gmail d from the official munual...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template