suche nach in der

pg_cancel_query> <PostgreSQL-Funktionen
Last updated: Fri, 18 May 2012

view this page in

pg_affected_rows

(PHP 4 >= 4.2.0, PHP 5)

pg_affected_rowsGibt die Anzahl betroffener Datensätze (Tupel) zurück

Beschreibung

int pg_affected_rows ( resource $result )

pg_affected_rows() gibt die Anzahl der Tupels (Instanzen/Datensätze/Zeilen) zurück, die von einer ausgeführten INSERT-, UPDATE- oder DELETE-Abfrage betroffen sind.

Hinweis:

Diese Funktion hieß vormals pg_cmdtuples().

Parameter-Liste

result

PostgreSQL Ergebniskennung, die (unter anderem) von den Funktionen pg_query(), pg_query_params() oder pg_execute() zurückgegeben wird.

Rückgabewerte

Die Anzahl der Zeilen, die von der Abfrage betroffen wurden. Wurde keine Zeile betroffen, wird 0 zurückgegeben.

Beispiele

Beispiel #1 pg_affected_rows()-Beispiel

<?php
$result 
pg_query($conn"INSERT INTO authors VALUES ('Orwell', 2002, 'Animal Farm')");

$cmdtuples pg_affected_rows($result);

echo 
$cmdtuples " Zeile(n) wurden betroffen.\n";
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

1 Zeile(n) wurden betroffen.

Siehe auch

  • pg_query() - Führt eine Abfrage aus
  • pg_query_params() - Sendet ein Kommando zum Server und wartet seine Ausführung ab. Getrennt vom SQL-Kommando können dabei Parameter übergeben werden.
  • pg_execute() - Fordert den Datenankserver auf, eine vorbereitete Anfrage mit den angegebenen Parametern auszuführen und wartet auf das Ergebnis
  • pg_num_rows() - Gibt die Anzahl der Zeilen in einem Abfrageergebnis zurück



add a note add a note User Contributed Notes
pg_affected_rows
05-Aug-2005 12:31
That's not quite true, I've been able to execute multiple queries in a single call just fine. In stead, it has to do with the fact this function returns the affected rows for the last executed query, not the last set of queries specified to a single call to pg_query.
29-Jun-2005 03:15
Concering Bruno Baguette's note:

The pg_query function only allows one query per function call.  When you do your
$sql="BEGIN;
INSERT ...
COMMIT;";
$result=pg_query($conn,$sql);
echo pg_affected_rows($result);

you get a zero, because only the BEGIN; is executed.

The single query per call is, I beleive, a PHP builtin protection against SQL injection attacks.  (Ie someone submitting a string paramter that ends the current query and appends another one)
Bruno Baguette
28-Jun-2005 10:45
Note that when you submit several SQL queries, within one BEGIN;COMMIT; like this one :

$SQLQuery = 'BEGIN;';
$SQLQuery.= 'INSERT INTO a (a,b) VALUES (1,2);';
$SQLQuery.= 'INSERT INTO b (ref_b,c) VALUES (2,5);';
$SQLQuery.= 'COMMIT;';

$HandleResults = pg_query($SQLQuery);
echo(pg_affected_rows($HandleResults));

pg_affected_rows() will return 0

pg_cancel_query> <PostgreSQL-Funktionen
Last updated: Fri, 18 May 2012