0

My test code:

    $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;

It says that mysql_affected_rows works with INSERT, UPDATE, REPLACE and DELETE。

Why I can also get the right result through mysql_affected_rows ?

Any help and suggestions will be highly appreciable。

GAMITG
  • 3,810
  • 7
  • 32
  • 51
tripleCC
  • 39
  • 8

2 Answers2

0

I suggest you must use

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

or

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

for updated method of accessing database since your method was deprecated in PHP 5.5.0

LeViNcE
  • 304
  • 1
  • 6
  • 15
0

Here is what I found on the internet.

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

See answers on the source at the bottom.

SergeyAn
  • 754
  • 6
  • 9