An error occurred while retrieving affected rows after updating mysql in php. solution:

Source: Internet
Author: User
The mysql_affected_rows function returns an abnormal value when the data before and after UPDATE is the same, next, I will introduce you to a friend who is interested in simple solutions. refer to the following. I learned from manual that the mysql_affected_rows function will return abnormal values when the data before and after UPDATE is the same,

The following is a convenient solution. the bdobrica at gmail dot com message is displayed on the official munual:
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.
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: I 've been tossing for a long time because of this small problem. I feel that php is too unclear.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.