mysqli_affected_rows 与 mysqli_num_rows的不同之处
来源:互联网 发布:mac air哪个键是insert 编辑:程序博客网 时间:2024/06/11 16:48
来源于http://stackoverflow.com/questions/25555758/what-is-the-difference-between-mysqli-affected-rows-and-mysqli-num-rows
问题如下:
The PHP docs for mysqli_num_rows says
Returns the number of rows in the result set.
The PHP docs for mysqli_affected_rows says
Returns the number of rows affected by the last INSERT, UPDATE, REPLACE or DELETE query.
_num_rows is called on a result, and _affected_rows is called on a connection. Since I think they do the same thing(correct this assumption if I'm wrong), I'm wondering whether one works better than the other, and which situations would call for which function.
Aren't number of rows affected and number of rows in the result set synonymous?
解答如下:
The PHP docs for mysqli_num_rows says
Returns the number of rows in the result set.
The PHP docs for mysqli_affected_rows says
Returns the number of rows affected by the last INSERT, UPDATE, REPLACE or DELETE query.
_num_rows is called on a result, and _affected_rows is called on a connection. Since I think they do the same thing(correct this assumption if I'm wrong), I'm wondering whether one works better than the other, and which situations would call for which function.
Aren't number of rows affected and number of rows in the result set synonymous?
num_rows
tells you how many rows there are in the result set you just selected with a SELECT
query. affected_rows
tells you how many rows where affected by an INSERT
, UPDATE
, REPLACE
or DELETE
query. The difference is obvious:
$resultSet = mysqli_query($c, 'SELECT ...');echo mysqli_num_rows($resultSet);
SELECT
result set goes into num_rows
.
mysqli_query($c, 'UPDATE ...');echo mysqli_affected_rows($c);
No result set, no num_rows
.
The PHP docs for mysqli_num_rows says
Returns the number of rows in the result set.
The PHP docs for mysqli_affected_rows says
Returns the number of rows affected by the last INSERT, UPDATE, REPLACE or DELETE query.
_num_rows is called on a result, and _affected_rows is called on a connection. Since I think they do the same thing(correct this assumption if I'm wrong), I'm wondering whether one works better than the other, and which situations would call for which function.
Aren't number of rows affected and number of rows in the result set synonymous?
- mysqli_affected_rows 与 mysqli_num_rows的不同之处
- 外企与国企的不同之处
- html5 与html4 的不同之处
- p[]与*p的不同之处
- HTML5与HTML4的不同之处
- startActivityForResult( )与startActivity( )的不同之处
- centos 与 ubuntu的不同之处
- startActivityForResult与startActivity的不同之处
- nasm 与 masm的不同之处
- setContentView与LayoutInflater的不同之处
- p[] 与 *p 的不同之处
- struts2与struts1的不同之处
- FLASH与EEPROM的不同之处
- Rest与WebService的不同之处
- C++与java的不同之处
- Groovy与java的不同之处
- startActivityForResult与startActivity的不同之处
- C++与JAVA的不同之处
- 面——经1
- [其它笔记001]:常用RGB颜色按灰度值排序
- 我的java学习路之I/O流
- 蓝桥杯:世纪末的星期
- C# 属性
- mysqli_affected_rows 与 mysqli_num_rows的不同之处
- 初学者的c普遍赋值问题
- sdut3257(质因数分解)立方和数
- ZJOI2017蒟蒻游记6 (day2)
- oracle部分查询语句
- 【经典策略系列】之 Dual Thrust 交易策略
- JSP —— jsp页面访问资源 路径问题
- 调试my eclipse
- May-Day训练赛题解