Home >Backend Development >PHP Problem >How to query record data in php pdo

How to query record data in php pdo

王林
王林Original
2020-10-12 10:00:212718browse

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 query record data in php pdo

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!

Statement:
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