下面就是文章的主要內容描述。
| 代碼如下 |
複製代碼 |
found_rows() : select row_count() : update delete insert |
注:需要配合相應的操作一起使用,否則返回的值只是1和-1(都是不正確的值)
樣本:
| 代碼如下 |
複製代碼 |
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(); -- 輸出3(返回新添加的記錄數),[注:如果使用insert into...values只返回1] select * from `MyTestTable`;select found_rows(); -- 輸出3(返回選擇的行數) update `MyTestTable` set `Name`='people';select row_count(); -- 輸出3(返回修改的行數) delete from `MyTestTable`;select row_count(); -- 輸出3(返回刪除的行數) |
php更新mysql後擷取影響的行數發生異常解決
| 代碼如下 |
複製代碼 |
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; } |