Home >Backend Development >PHP Problem >How to query record data in php pdo
php pdo method of querying record data: You can use the fetchAll() function to query, such as [$rows = $q->fetchAll();]. You can also use the sql count function to query, such as ["SELECT count(*) from db;"].
How to get the correct number of rows in the SELECT result
(Recommended tutorial: php video tutorial)
1. Use the fetchAll function
$q = $db->query("SELECT ..."); $rows = $q->fetchAll(); $rowCount = count($rows);
2. Use the sql count function
$q = $db->query("SELECT count(*) from db;"); $rows = $q->fetch(); $rowCount = $rows[0];
In terms of efficiency, the second method has more advantages.
Related recommendations: php training
The above is the detailed content of How to query record data in php pdo. For more information, please follow other related articles on the PHP Chinese website!