Example #1
0
<?php

error_reporting(E_ALL);
include 'config.inc';
$db = pg_connect($conn_str);
$fields = array('num' => '1234', 'str' => 'XXX', 'bin' => 'YYY');
$ids = array('num' => '1234');
if (!pg_delete($db, $table_name, $ids)) {
    echo "Error\n";
} else {
    echo "Ok\n";
}
 * these will include annual netgwcu values to be calculated from the annual gwcu and recharge values
 * (keeping them separate in the data is important for subzone calculations)
 * the year range and impacted stream reaches and most other data can be determined from
 *   the zone's stream depletion input data records for this "scenario"
 * each record represents one response function application
 *   in other words, each record will be used to create a time series of stream depletions (usually 20 years long)
 *   these stream depletions will be saved separately in the pg database to be aggregated later via queries
 *   to create exactly the reposne that the user desires (without having to reconvolute the same data over and over)   
 */
//$excitation_array=array(2001=>5.0,2002=>10.0,2003=>0.0,2004=>15.0);
// clear out the previous data for this stream depletion scenario
$delete_array['model_version'] = $rgmodelversion;
$delete_array['nzone'] = $rgresponsezone;
$delete_array['nsubzone'] = $rgresponsezone;
$delete_array['nscenario'] = $rgstreamdepletionscenario;
pg_delete($pgconnection, $rgstreamdepletiondatatable, $delete_array);
// subtimestep
$subtimestepcount = $options[RGSUBTIMESTEPCOUNT];
// get the str depl scenario records
$query = "SELECT model_version, nzone, nsubzone, nreach, nscenario, nyear,";
$query .= " subzone_gwcu_af, subzone_recharge_af, zone_gwcu_af, zone_recharge_af, streamflow_aprsep_af,";
$query .= " grouping_type, streamflow_avg_af, resp_fn_type, resp_fn_ndx";
$query .= " FROM {$rgstreamdepletionscenariotable}";
$query .= " WHERE model_version={$rgmodelversion}";
$query .= " AND nzone={$rgresponsezone}";
$query .= " AND nsubzone={$rgresponsesubzone}";
$query .= " AND nscenario={$rgstreamdepletionscenario}";
$query .= " ORDER BY nyear, nreach";
$results = pg_query($pgconnection, $query);
$recordcount = 0;
$model_version = array();
Example #3
0
<?php

require_once 'config.inc';
$dbh = pg_connect($conn_str);
$tbl_name = 'test_47199';
@pg_query("DROP TABLE {$tbl_name}");
pg_query("CREATE TABLE {$tbl_name} (null_field INT, not_null_field INT NOT NULL)");
pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 1));
pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 2));
var_dump(pg_fetch_all(pg_query('SELECT * FROM ' . $tbl_name)));
$query = pg_delete($dbh, $tbl_name, array('null_field' => NULL, 'not_null_field' => 2), PGSQL_DML_STRING | PGSQL_DML_EXEC);
echo $query, "\n";
$query = pg_update($dbh, $tbl_name, array('null_field' => NULL, 'not_null_field' => 0), array('not_null_field' => 1, 'null_field' => ''), PGSQL_DML_STRING | PGSQL_DML_EXEC);
echo $query, "\n";
var_dump(pg_fetch_all(pg_query('SELECT * FROM ' . $tbl_name)));
@pg_query("DROP TABLE {$tbl_name}");
pg_close($dbh);
echo PHP_EOL . "Done" . PHP_EOL;
Example #4
0
<?php

include 'config.inc';
$conn = pg_connect($conn_str);
pg_query('CREATE SCHEMA phptests');
pg_query('CREATE TABLE foo (id INT, id2 INT)');
pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)');
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1));
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2));
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2));
pg_insert($conn, 'foo', array('id' => 3, 'id2' => 3));
pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 1));
pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2));
pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
pg_delete($conn, 'foo', array('id' => 1, 'id2' => 0));
pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2));
var_dump(pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 1));
pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
var_dump(pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3), PGSQL_DML_STRING));
var_dump(pg_fetch_all(pg_query('SELECT * FROM foo')));
var_dump(pg_fetch_all(pg_query('SELECT * FROM phptests.foo')));
/* Inexistent */
pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2));
var_dump(pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
pg_query('DROP TABLE foo');
pg_query('DROP TABLE phptests.foo');
pg_query('DROP SCHEMA phptests');
Example #5
0
        }
        if ($table == 'public.location_user' || $table == 'public.group_user') {
            break;
            //relasjonstabeller skal ikke returnere noen id
        }
        $result = pg_query($conn, "select currval('" . $table . "_" . $json_object->table . "_id_seq');");
        break;
    case "update":
        $result = pg_update($conn, $table, $values, $conditions);
        break;
    case "select":
        $sql = "select " . implode(", ", $to_select) . " from " . $table . " where " . implode(" and ", $conditions_array) . ";";
        $result = pg_query($conn, $sql);
        break;
    case "delete":
        $result = pg_delete($conn, $table, $conditions);
        break;
    case "sql":
        $result = pg_query($conn, $sql);
        $str = "[";
        while ($result_row = pg_fetch_assoc($result)) {
            $str .= json_encode($result_row) . ",";
        }
        $str = rtrim($str, ",");
        $str .= "]";
        echo $str;
        exit;
}
if (is_bool($result)) {
    echo $result ? 'true' : 'false';
    exit;
Example #6
0
 /**
  * Delete data with param
  * \param[in] table name of table
  * \param[in] condition associative array of field=>value
  */
 function delete($table, $cond, $options = PGSQL_DML_EXEC)
 {
     $res = pg_delete($this->conn, $table, $cond, $options);
     if (!$res) {
         throw new Exception(DB_ERR . 'Delete: ' . pg_last_error($this->conn));
     }
 }