This example describes how to change 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 changes in the line, in PHP to provide the MySQL function to get the last execution of the query affected by the number of records: Mysql_affected_rows (), return the most recent connection handle associated with the insert,update or DELETE The number of record rows affected by the query. Found_rows (): Select Row_count (): Update delete insert.
Here is the main description of the article, the code is as follows:
Copy Code code as follows:
Found_rows (): Select
Row_count (): UPDATE Delete Insert
Note: You need to work with the appropriate operation, otherwise the value returned is only 1 and 1 (all 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 you use Insert into...values only return 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 rows modified)
Delete from ' mytesttable '; select Row_count (); --Output 3 (returns the number of rows deleted)
PHP update MySQL After the impact of the number of rows to get the exception resolved, 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 will help you with your PHP program design.