How can I count the numbers of rows that a MySQL query returned?

后端 未结 11 1905
北海茫月
北海茫月 2020-11-28 04:51

How can I count the number of rows that a MySQL query returned?

11条回答
  •  离开以前
    2020-11-28 05:39

    Assuming you're using the mysql_ or mysqli_ functions, your question should already have been answered by others.

    However if you're using PDO, there is no easy function to return the number of rows retrieved by a select statement, unfortunately. You have to use count() on the resultset (after assigning it to a local variable, usually).

    Or if you're only interested in the number and not the data, PDOStatement::fetchColumn() on your SELECT COUNT(1)... result.

提交回复
热议问题