1

I have just noticed that where mysql_num_rows should return the number of rows returned for either SELECT or SHOW commands, returns 0 for SHOW TABLE command specifically.

Instead it shows the affected rows count instead of the num rows.

Can anyone please tell me if this is a bug or if am I missing anything here?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Vish
  • 4,508
  • 10
  • 42
  • 74

4 Answers4

3

SHOW TABLE command is used to Show you table name in your database . On the other hand , mysql_num_rows is used to count how many result got from your query. This query is depend on your requirement basis ...

1

As stated on the PHP documentation page:

Retrieves the number of rows from a result set. This command is only valid for statements like SELECT or SHOW that return an actual result set.

My guess is that SHOW TABLES is not a technical query that would produce the type of result set that mysql_num_rows enumerates.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
1

These "helper" functions (such as SHOW, EXPLAIN, DESCRIBE etc.) won't let you issue their results like you would in a regular table.

But if you're looking for how you can do this, for SHOW TABLES you can do

SELECT `table_name` FROM `information_schema`.`tables`
WHERE `table_schema`=DATABASE()
-- DATABASE() selects current database name
-- you can use the name of any database as a string instead

So basically you can use the information_schema database to get that information.

inhan
  • 7,394
  • 2
  • 24
  • 35
0

It was a bug in mysql, fixed it with the update.

Vish
  • 4,508
  • 10
  • 42
  • 74