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 Code |
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)
Example:
code as follows |
copy code |
Drop database if exists ' mytest '; CREATE database ' mytest '; use ' mytest '; Drop table if exists ' mytesttable '; CREATE TABLE ' mytesttable ' (' ID ' int, ' Name ' varchar); 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 R Ow_count (); --Output 3 (returns the number of modified rows) Delete from ' mytesttable '; select Row_count ();--Output 3 (returns the number of rows deleted) |
PHP update MySQL After getting affected by the number of rows occurred exception resolved
The code is as follows |
Copy Code |
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; } |
http://www.bkjia.com/PHPjc/630723.html www.bkjia.com true http://www.bkjia.com/PHPjc/630723.html techarticle a php update mysql after getting the number of changed rows, in PHP provides the MySQL function to get the last execution of the query affected by the number of records: Mysql_affected_rows (), return the last time with the connection handle close ...