Php updates mysql and obtains the number of changed rows. After updating mysql, a php instance obtains the number of changed rows. in php, the mysql function is provided to obtain the number of records affected by the last query: mysql_affected_rows (), returns the number of changed rows after the last php update mysql with the connection handle. provides the mysql function in php to obtain the number of records affected by the last query: mysql_affected_rows (), returns the number of rows affected by the last INSERT, UPDATE, or DELETE query associated with the connection handle. FOUND_ROWS (): select ROW_COUNT (): update delete insert.
The following describes the main content of the article.
The code is as follows: |
|
Found_rows (): select Row_count (): update delete insert |
Note: it must be used together with the corresponding operation. Otherwise, the returned values are only 1 and-1 (both incorrect values)
Example:
The code is 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', 'role 1' union all Select '2', 'role 2' union all Select '3', 'role 3 '; Select row_count (); -- output 3 (returns the number of newly added Records). [note: If insert into... values is used, only 1 is returned.] Select * from 'mytesttable'; select found_rows (); -- output 3 (return the number of selected rows) Update 'mytesttable' set 'name' = 'people'; select row_count (); -- output 3 (returns the number of modified rows) Delete from 'mytesttable'; select row_count (); -- output 3 (return the number of deleted rows) |
An error occurred while retrieving affected rows after updating mysql in php.
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; } |
Callback (), returns the last connection handle close...