Hướng dẫn dùng sqlrowcount trong PHP
(PHP 5 >= 5.1.0, PHP 7, PHP 8, PECL pdo >= 0.1.0) PDOStatement::rowCount — Returns the number of rows affected by the last SQL statement Descriptionpublic PDOStatement::rowCount(): int If the last SQL statement executed by the associated
ParametersThis function has no parameters. Return ValuesReturns the number of rows. ExamplesExample #1 Return the number of deleted rows PDOStatement::rowCount() returns the number of rows affected by a DELETE, INSERT, or UPDATE statement.
The above example will output something similar to: Return number of rows that were deleted: Deleted 9 rows. Example #2 Counting rows returned by a SELECT statement For most databases, PDOStatement::rowCount() does not return the number of rows affected by a SELECT statement. Instead, use PDO::query() to issue a SELECT COUNT(*) statement with the same predicates as your intended SELECT statement, then use PDOStatement::fetchColumn() to retrieve the number of matching rows.
"There are " . $count . " matching records.";
The above example will output something similar to: There are 2 matching records. See Also
Ome Ko ¶ 11 years ago
Matt ¶ 14 years ago
Daniel Karp ¶ 10 years ago
leandro at marquesini dot com ¶ 10 years ago
$data = $stmt->fetch()) { sERGE-01 ¶ 8 years ago
$sth = $this->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL))) gunnrosebutpeace at gmail dot com ¶ 14 years ago
xmt at abv dot bg ¶ 4 years ago
user at nospam dot example dot com ¶ 8 years ago
info at buylikesandviews dot com ¶ 7 years ago
bohwaz ¶ 3 years ago
lsrzj at facebook ¶ 6 years ago
e dot sand at elisand dot com ¶ 13 years ago
@rhavendc (twitter) ¶ 6 years ago
phpnet at maya-control dot ro ¶ 8 years ago
e dot sand at elisand dot com ¶ 13 years ago
query(/* ... */) { |