mysqli_affected_rows和mysqli_num_rows有什么区别? [英] What is the difference between mysqli_affected_rows and mysqli_num_rows?

查看:86
本文介绍了mysqli_affected_rows和mysqli_num_rows有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关mysqli_num_rows的PHP文档

返回结果集中的行数.

Returns the number of rows in the result set.

有关mysqli_affected_rows的PHP文档

返回受上一次INSERT,UPDATE,REPLACE或DELETE查询影响的行数.

Returns the number of rows affected by the last INSERT, UPDATE, REPLACE or DELETE query.

在结果上调用

_num_rows,在连接上调用_affected_rows.由于我认为他们做同样的事情(如果我错了,请更正此假设),我想知道一种方法是否比另一种效果更好,以及哪种情况需要哪种功能.

_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告诉您您刚刚通过SELECT查询选择的结果集中有多少行. 告诉您INSERTUPDATEREPLACEDELETE查询影响的行数.区别很明显:

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结果集放入num_rows.

mysqli_query($c, 'UPDATE ...');
echo mysqli_affected_rows($c);

没有结果集,没有num_rows.

这篇关于mysqli_affected_rows和mysqli_num_rows有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆