Updating Data in PostgreSQL


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
  if ($db = @pg_connect('host=localhost port=5432
    dbname=hoshmand user=postgres
    password=abc123')) {
    require_once '';
    $data = array(
      'quote' => pg_escape_string($_POST['quote']),
      'author' => pg_escape_string($_POST
      'year' => intval($_POST['year'])
    pg_insert($db, 'quotes', $data);
    echo 'Quote saved.';
  } else {
    echo 'Connection failed.';

by BrainBellupdated