Home > Database > Mysql Tutorial > Why Does My MySQLi COUNT(*) Query Return 1 Instead of the Actual Row Count?

Why Does My MySQLi COUNT(*) Query Return 1 Instead of the Actual Row Count?

DDD
Release: 2024-12-09 10:17:10
Original
841 people have browsed it

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];
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template