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

How to query record data in php pdo

王林
Release: 2023-03-06 16:14:02
Original
2725 people have browsed it

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

2. Use the sql count function

$q = $db->query("SELECT count(*) from db;");
$rows = $q->fetch();
$rowCount = $rows[0];
Copy after login

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!

Related labels:
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