mysql_num_rows和mysql_affected_rowsreturn执行时结果相同SELECTSQL

mysql_num_rows and mysql_affected_rows return the same result when executing SELECT SQL

我的测试代码:

    $connection = mysql_connect('localhost', 'root', '') or die(mysql_error());

    mysql_select_db("chaoge", $connection);

    mysql_query("SET NAMES UTF8", $connection);

    $rs = mysql_query("SELECT * FROM babel_node WHERE nod_pid = 2101", $connection);

    $nu = mysql_affected_rows();
    echo $nu;

它说 mysql_affected_rows 与 INSERT、UPDATE、REPLACE 和 DELETE 一起工作。

为什么我通过mysql_affected_rows也能得到正确的结果?

如有任何帮助和建议,我们将不胜感激。

我建议你一定要用

MySQLi http://php.net/manual/en/book.mysqli.php

PDO_MySQL http://php.net/manual/en/ref.pdo-mysql.php

更新了访问数据库的方法,因为您的方法在 PHP 5.5.0

中已弃用

这是我在网上找到的。

mysql_affected_rows() for a SELECT indicates the number of rows which were found. mysql_num_rows() indicates how many rows were actually returned. They may not be the same, IIRC, if you have a LIMIT clause or similar. GROUP BY may also cause a difference.

Source

查看底部来源的答案。