Home >Database >Mysql Tutorial >Why Does My MySQLi COUNT(*) Query Return 1 Instead of the Actual Row Count?
MySQLi Count(*) Query Incorrectly Returns One
When attempting to determine the number of rows within a table using the MySQLi extension, a user encountered an issue where the count() function consistently returned the value 1. Despite executing the same query in phpMyAdmin produced the intended result, the $count[0] method returned the value NULL.
Correct Implementation
To rectify this issue, it is crucial to retrieve the sole record returned by the count() query, as it encapsulates the desired result. The following code snippet illustrates the correct implementation:
$result = $db->query("SELECT COUNT(*) FROM `table`"); $row = $result->fetch_row(); echo '#: ', $row[0];
The above is the detailed content of Why Does My MySQLi COUNT(*) Query Return 1 Instead of the Actual Row Count?. For more information, please follow other related articles on the PHP Chinese website!