Updating Data in PostgreSQL


 pg_insert() 


Another way to insert or update data in PostgreSQL comes in the form of the functions pg_insert() and pg_update(). The first parameter must be the database handle, the second parameter is the table to be inserted into/updated, and the third parameter contains some data in the form of an associative array (column names are the keys). In the event of an UPDATE SQL statement, the update condition must also be submitted as an array in the fourth parameter of the function. The preceding code shows how to insert data.

Sending SQL to PostgreSQL (pg_insert.php; excerpt)
 <?php   if ($db = @pg_connect('host=localhost port=5432     dbname=phrasebook user=postgres     password=abc123')) {     require_once 'stripFormSlashes.inc.php';     $data = array(       'quote' => pg_escape_string($_POST['quote']),       'author' => pg_escape_string($_POST          ['author']),       'year' => intval($_POST['year'])     );     pg_insert($db, 'quotes', $data);     echo 'Quote saved.';     pg_close($db);   } else {     echo 'Connection failed.';   } ?> 




PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net