suche nach in der

pg_version> <pg_untrace
Last updated: Fri, 18 May 2012

view this page in

pg_update

(PHP 4 >= 4.3.0, PHP 5)

pg_update Aktualisiert eine Tabelle

Beschreibung

mixed pg_update ( resource $connection , string $table_name , array $data , array $condition [, int $options = PGSQL_DML_EXEC ] )

pg_update() überschreibt alle Datensätze in table_name, deren Werte denen in condition entsprechen, mit den Werten aus data. Falls options angegeben sind, wird pg_convert() mit den angegebenen Flags auf data angewendet.

Warnung

Diese Funktion ist EXPERIMENTELL. Das Verhalten, der Funktionsname und alles Andere, was hier dokumentiert ist, kann sich in zukünftigen PHP-Versionen ohne Ankündigung ändern. Seien Sie gewarnt und verwenden Sie diese Funktion auf eigenes Risiko.

Parameter-Liste

connection

PostgreSQL Verbindungskennung.

table_name

Name der Tabelle, die aktualisiert werden soll.

data

Ein array, dessen Schlüssel Feldnamen von table_name sind und mit dessen Werten die Tabelle aktualisiert wird.

condition

Ein array, dessen Schlüssel Feldnamen von table_name sind und das die Werte enthält, die in table_name überschrieben werden sollen. (Die Gleichheit dieser Werte ist die Bedingung zum Überschreiben.)

options

Jede Kombination aus PGSQL_CONV_OPTS, PGSQL_DML_NO_CONV, PGSQL_DML_EXEC oder PGSQL_DML_STRING. Falls PGSQL_DML_STRING in den options enthalten ist, wird der Abfragestring zurückgegeben.

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben. Gibt einen string zurück, falls PGSQL_DML_STRING mit dem Parameter options übergeben wurde.

Beispiele

Beispiel #1 pg_update() Beispiel

<?php 
  $db 
pg_connect('dbname=foo');
  
$data = array('field1'=>'AA''field2'=>'BB');
  
  
// Das ist sicher, da $_POST automatisch konvertiert wird
  
$res pg_update($db'post_log'$_POST$data);
  if (
$res) {
      echo 
"Daten wurden aktualisiert: $res\n";
  } else {
      echo 
"Falsche Eingabe\n";
  }
?>

Siehe auch

  • pg_convert() - Konvertiert die Werte eines assoziativen Arrays in passende Werte für SQL-Kommandos.



add a note add a note User Contributed Notes
pg_update
jhooks
13-Apr-2006 04:54
> Return Values
>
> Returns TRUE on success or FALSE on failure. Returns string if
> PGSQL_DML_STRING is passed via options.

I have found in my copy of PHP (version 4.4.0) that if you use the 'PGSQL_DML_STRING' option, the function does not execute any query.  It merely returns the query which would have been executed. 

Another thing I noticed, pg_update does not seem to make use of pg_trace (atleast in 4.4.0).

PS this isn't a bug report, just an explanation of some undocumented features I noticed.  As the manual says, the function is still in development so this behaviour may differ from version to version.
sdibb at myway dot com
14-Jun-2005 04:26
This function is similar to PEAR::DB's autoExecute() function, with the only difference being that the where clause is an array instead of a string.

Also, if you want to use your instance of the DB class with this function, you can reference the existing resource connection with $db->connection.

An example would be:
<?
     pg_update
($db->connection, $arr_update, $arr_where);
?>

pg_version> <pg_untrace
Last updated: Fri, 18 May 2012