How to get the number of rows changed after php updates mysql, the number of mysql rows
The example in this article describes how to obtain the number of changed rows after PHP updates mysql. Share it with everyone for your reference. The specific analysis is as follows:
Get the number of changed rows after a php updates mysql. Provide a mysql function in php to get the number of records affected by the last executed query: mysql_affected_rows(), which returns the most recent INSERT, UPDATE or DELETE query associated with the connection handle. Number of record rows affected.FOUND_ROWS(): select ROW_COUNT():update delete insert.
The following is the main content description of the article, the code is as follows:
Copy code The code is as follows:
found_rows():select
row_count(): update delete insert
Note: It needs to be used in conjunction with the corresponding operation, otherwise the returned values are only 1 and -1 (both incorrect values)
php sample code is as follows:
Copy code 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','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 insert into...values is used, only 1 is returned]
select * from `MyTestTable`;select found_rows(); -- Output 3 (returns the number of selected rows)
update `MyTestTable` set `Name`='people';select row_count(); -- Output 3 (return the number of modified rows)
delete from `MyTestTable`;select row_count(); -- Output 3 (returns the number of deleted rows)
After PHP updates mysql, an exception occurs when obtaining the number of affected rows. The code is as follows:
Copy code 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;
}
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/932472.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/932472.htmlTechArticleHow to get the changed row number after php updates mysql, mysql row number This article tells the example of getting the change after php updates mysql Row number method. Share it with everyone for your reference. The specific analysis is as follows:...