PHP update MySQL After getting the method of changing the number of rows, MySQL line number _php tutorial

Source: Internet
Author: User
Tags php sample code

PHP update MySQL After the method of changing the number of rows, MySQL line number


The example in this article describes how to get a change in the number of rows after PHP updates mysql. Share to everyone for your reference. The specific analysis is as follows:

A php update MySQL to get the number of changed rows, in PHP to provide MySQL function to get the last execution of the query affected by the number of records: Mysql_affected_rows (), return the most recent insert,update or DELETE associated with the connection handle The number of record rows affected by the query. Found_rows (): Select Row_count (): Update delete insert.

Here is the main content of the article description, the code is as follows:
Copy the Code code as follows: Found_rows (): Select
Row_count (): UPDATE Delete Insert

Note: You need to work with the appropriate operation, otherwise the returned value is only 1 and 1 (both are incorrect values)

The

PHP sample code is as follows:
Copy code code as follows: Drop database if exists ' mytest ';
CREATE database ' mytest ';
use ' mytest ';
drop table if exists ' mytesttable ';
CREATE TABLE ' mytesttable ' (' ID ' int, ' Name ' varchar (10));
INSERT INTO ' mytesttable ' (' ID ', ' Name ')
Select ' 1 ', ' role1 ' union ALL
Select ' 2 ', ' role2 ' union ALL
Select ' 3 ', ' role3 ';
Select Row_count ();--Output 3 (returns the number of newly added records), [Note: If using insert Into...values only returns 1]
Select * from ' mytesttable '; Select found _rows (); --Output 3 (returns the number of rows selected)
Update ' mytesttable ' set ' Name ' = ' people '; select Row_count ();--Output 3 (returns the number of modified rows)
Delete from ' Mytestt Able '; select Row_count (); --Output 3 (returns the number of deleted rows)
The number of rows affected by PHP update MySQL has been resolved with an exception, the code is as follows:
Copy code code 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;
}

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/932472.html www.bkjia.com true http://www.bkjia.com/PHPjc/932472.html techarticle PHP update MySQL After the method of changing the number of rows, MySQL line number This article describes the PHP update MySQL after the method of changing the number of rows. Share to everyone for your reference. The specific analysis is as follows: ...

  • 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.