PDOStatement::rowCount

(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

Beschreibung

public PDOStatement::rowCount(): int

PDOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.

If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.

Hinweis:

This method returns "0" (zero) with the SQLite driver at all times, and with the PostgreSQL driver only when setting the PDO::ATTR_CURSOR statement attribute to PDO::CURSOR_SCROLL.

Parameter-Liste

Diese Funktion besitzt keine Parameter.

Rückgabewerte

Returns the number of rows.

Beispiele

Beispiel #1 Return the number of deleted rows

PDOStatement::rowCount() returns the number of rows affected by a DELETE, INSERT, or UPDATE statement.

<?php
/* Delete all rows from the FRUIT table */
$del $dbh->prepare('DELETE FROM fruit');
$del->execute();

/* Return number of rows that were deleted */
print("Return number of rows that were deleted:\n");
$count $del->rowCount();
print(
"Deleted $count rows.\n");
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

Return number of rows that were deleted:
Deleted 9 rows.

Beispiel #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.

<?php
$sql 
"SELECT COUNT(*) FROM fruit WHERE calories > 100";
$res $conn->query($sql);
$count $res->fetchColumn();

print 
"There are " .  $count " matching records.";

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

There are 2 matching records.

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

nastrozole Till salu. Anastrozole snabb leverans - billiga Anastrozole inget recept.

Till salu Anastrozole. Anastrozole snabb leverans Behöver du kvalitetsmedicin utan krångel? Vårt onlineapotek är här för att hjälpa dig! Bl ...

Geschrieben von travelder am 18.06.2026 09:33:13
Forum: Bücher-Forum
italin Am billigsten. Ich brauche Ritalin für Visa - wie kaufe ich Over the Counter

Am billigsten Ritalin. Ich brauche Ritalin für Visa Sie suchen erstklassige Medikamente, ohne das Haus zu verlassen? Suchen Sie nicht weiter! Uns ...

Geschrieben von drawer am 18.06.2026 09:32:55
Forum: Fragen/Vorschläge zum Forum
lprazolam Pris. Laveste priser på Internettet Alprazolam - køb Alprazolam billig ude

Pris Alprazolam. Laveste priser på Internettet Alprazolam Leder du efter førsteklasses medicin uden at forlade hjemmet? Stop med at lede! Vores ...

Geschrieben von drawer am 18.06.2026 09:32:11
Forum: Netzwerk &amp; Internet
lprazolam Snabb leverans. Köp Alprazolam online över natten - Alprazolam köpa. Troll

Snabb leverans Alprazolam. Köp Alprazolam online över natten Behöver du kvalitetsmedicin utan krångel? Vårt onlineapotek är här för att hj ...

Geschrieben von travelder am 18.06.2026 09:31:37
Forum: Bücher-Forum