Example #1
0
	function put_array($table_name, $array, $db=NULL)
	{
		// experimental ??uses pg_insert(to put an array into a table )
		//... you'll want to make sure the fields match perfectly !!

		if ($db == NULL) $db = $this->db;
		pg_insert($db, $table_name, $array);

	}
function dbInsert($table_name, $assoc_array)
{
    global $database_connection;
    $result = pg_insert($database_connection, $table_name, $assoc_array);
    if ($result) {
        return dbLastInsertId();
    } else {
        die("PG Error: " . pg_result_error($result));
    }
}
Example #3
0
 /**
  * Insert data with param
  * \param[in] table name of table
  * \param[in] data associative array of field=>value
  * \param[in] options =PGSQL_DML_EXEC if not escaped strings present
  */
 function insert($table, $data, $options = PGSQL_DML_EXEC)
 {
     if (!is_array($data)) {
         throw new Exception(DB_ERR . "Illegal data for insert");
     }
     $res = pg_insert($this->conn, $table, $data, $options);
     if (!$res) {
         throw new Exception(DB_ERR . 'Insert: ' . pg_last_error($this->conn));
     }
 }
Example #4
0
 function do_blipp($price)
 {
     $date = new DateTime(null, new DateTimeZone('UTC'));
     $date_str = $date->format('Y-m-d H:i:s');
     //Free coffee
     if ($this->is_coffee_free()) {
         $price = 0;
     } else {
         $balance = $this->get_balance();
         if ($balance < $price) {
             throw new PaymentException('Insufficient funds.');
         }
         $new_balance = $balance - $price;
         $this->set_balance($new_balance);
     }
     //Put the order in the db
     $order = pg_query_params($this->c, "INSERT INTO baljan_order (made, put_at, user_id, paid, currency, accepted) VALUES (\$1, \$2, \$3, \$4, 'SEK', true) RETURNING id", array($date_str, $date_str, $this->get_uid(), $price));
     $order_good = pg_insert($this->c, "baljan_ordergood", array('made' => $date_str, 'order_id' => pg_fetch_array($order)['id'], 'good_id' => 1, 'count' => 1));
 }
Example #5
0
		function insert($table, $data) {
			return $this->q(pg_insert($this->connection, $table, $data, PGSQL_DML_STRING));
		}
Example #6
0
<?php

include 'config.inc';
$conn = pg_connect($conn_str);
pg_query('CREATE SCHEMA phptests');
pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)');
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1));
pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2));
var_dump(pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
var_dump(pg_select($conn, 'phptests.foo', array('id' => 1)));
pg_query('DROP TABLE phptests.foo');
pg_query('DROP SCHEMA phptests');
Example #7
0
<?php

require_once 'config.inc';
$dbh = @pg_connect($conn_str);
if (!$dbh) {
    die("Could not connect to the server");
}
pg_query("CREATE TABLE php_test (id SERIAL, tm timestamp NOT NULL)");
$values = array('tm' => 'now()');
pg_insert($dbh, 'php_test', $values);
$ids = array('id' => 1);
pg_update($dbh, 'php_test', $values, $ids);
pg_query($dbh, "DROP TABLE php_test");
pg_close($dbh);
?>
===DONE===
        $query .= " AND nreach={$rgstreamreach}";
        $query .= " AND nrspfn={$rgrespfnversion}";
        $query .= " AND group_ndx={$rggroup_ndx}";
        $query .= " ORDER BY timestep ASC";
        $results = pg_query($pgconnection, $query);
        while ($row = pg_fetch_row($results)) {
            $response_array[$row[0]] = $row[1];
        }
        $response_arrays[$ndx] = $response_array;
    }
    // run the convolution and create the stream depletion time series
    $results = hybrid_convolution_linear_scaling_multiple_ranges_subzone($zone_grpval_array, $zone_gwcu_array, $zone_recharge_array, $subzone_gwcu_array, $subzone_recharge_array, $response_arrays, $subtimestepcount, $linex_array, $liney_array, $lineslope_array, $group_range_array);
    // save the stream depletion time series back to a pg table
    if (count($results)) {
        foreach ($results as $ndx => $value) {
            $insert_array['model_version'] = $rgmodelversion;
            $insert_array['nzone'] = $rgresponsezone;
            $insert_array['nsubzone'] = $rgresponsesubzone;
            $insert_array['nscenario'] = $rgstreamdepletionscenario;
            $insert_array['nreach'] = $rgstreamreach;
            $insert_array['nyear'] = $startyear;
            $absolutetimestep = $ndx + ($startyear - 1900) * $subtimestepcount;
            $insert_array['ntimestep'] = $absolutetimestep;
            //if(array_key_exists($absolutetimestep,$credit_array)) {
            //	$value += $credit_array[$absolutetimestep];
            //}
            $insert_array['depletion_af'] = $value;
            pg_insert($pgconnection, $rgstreamdepletiondatatable, $insert_array);
        }
    }
}
Example #9
0
$current_table = $_POST['current_table'];
$sequence_step = $_POST['sequence_step'];
$next_step = $sequence_step + 1;
$names = getColumnNames($current_table);
$collection = array();
$data2fields = array();
for ($i = 0; $i < $current_field_count; $i++) {
    $field = strval($_POST['field_' . $i]);
    if ($names[$i] == 'password') {
        $md5 = md5($field);
        $field = $md5;
    }
    array_push($collection, $field);
    $data2fields[$names[$i]] = $collection[$i];
}
$success = pg_insert($connection, $current_table, $data2fields);
if ($success) {
    echo 'Poprawnie dodano wiersz do bazy danych.<br>';
    echo '<form action="index.php" method="post"><input type="hidden" name="sequence_step" value="' . $next_step . '">';
    rebuildStoredIdMap();
    postStoredIdMap();
    echo '<input type="submit" value="Przejdź do kolejnego kroku"></form>';
    echo '<form action="index.php" method="post"><input type="hidden" name="sequence_step" value="' . $sequence_step . '">';
    rebuildStoredIdMap();
    postStoredIdMap();
    echo '<input type="submit" value="Powtórz jeszcze raz ten sam krok"></form><hr>';
} else {
    echo 'Wystąpił błąd podczas przetwarzania zapytania.<hr>';
}
echo '<pre>';
print_r($stored_id_map);
Example #10
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 #11
0
<?php

require_once 'config.inc';
$dbh = @pg_connect($conn_str);
if (!$dbh) {
    die("Could not connect to the server");
}
pg_query("CREATE TABLE php_test (id SERIAL PRIMARY KEY, time TIMESTAMP NOT NULL DEFAULT now())");
pg_insert($dbh, 'php_test', array());
var_dump(pg_fetch_assoc(pg_query("SELECT * FROM php_test")));
pg_query($dbh, "DROP TABLE php_test");
pg_close($dbh);
?>
===DONE===
Example #12
0
 function insert($table, $values)
 {
     return pg_insert($this->connection, $table, $values);
 }
Example #13
0
<?php

error_reporting(E_ALL);
include 'config.inc';
$db = pg_connect($conn_str);
$fields = array('num' => '1234', 'str' => 'AAA', 'bin' => 'BBB');
pg_insert($db, $table_name, $fields) or print "Error in test 1\n";
echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING) . "\n";
echo "Ok\n";
Example #14
0
<?php

/* @author Alan Harder */
if ($_GET['version']) {
    require_once '/config/dbconfig.php';
    $db = @pg_connect("user={$dbuser} password={$dbpass} host={$dbserver} dbname={$dbname}");
    if (!$db) {
        die('DB error');
    }
    $voter = $_SERVER['HTTP_X_FORWARDED_FOR'];
    if (empty($voter)) {
        $voter = $_SERVER['REMOTE_ADDR'];
    }
    if ($_GET['rating'] == 1) {
        pg_insert($db, 'jenkins_good', array('version' => $_GET['version'], 'voter' => $voter));
    } else {
        $row = array('version' => $_GET['version'], 'voter' => $voter, 'rollback' => $_GET['rating'] == -1);
        $issue = (int) preg_replace('/^(JENKINS|HUDSON)-/i', '', $_GET['issue']);
        if ($issue > 0) {
            $row['issue'] = $issue;
        }
        pg_insert($db, 'jenkins_bad', $row);
    }
    pg_close($db);
}
Example #15
0
 * @copyright  Copyright (c) WGBH (http://www.wgbh.org/). All Rights Reserved.
 * @license    http://www.gnu.org/licenses/gpl.txt GPLv3
 * @version    GIT: <$Id>
 * @link       https://github.com/avpreserve/AMS
 */
$dbconnection = pg_connect("host=localhost port=5432 dbname=mint user=mint password=mint");
if ($dbconnection) {
    if (isset($_REQUEST['mint_id'])) {
        if ($_REQUEST['mint_id'] == '') {
            $p_query = pg_query($dbconnection, "SELECT nextval('seq_users_id')");
            $user_id = pg_fetch_row($p_query);
            $username = explode('@', $_REQUEST['username']);
            $random = rand(1, 99);
            $final_username = $username[0] . '_' . $random;
            $data = array('login' => $final_username, 'first_name' => $_REQUEST['first_name'], 'last_name' => $_REQUEST['last_name'], 'email' => $_REQUEST['username'], 'md5_password' => md5($final_username . 'x0h0@123'), 'organization_id' => 1, 'account_created' => date('Y-m-d'), 'active_account' => 't', 'rights' => $_REQUEST['rights'], 'users_id' => $user_id[0]);
            $result = pg_insert($dbconnection, 'users', $data);
            if ($result) {
                $email = $_REQUEST['username'];
                $p_query = pg_query($dbconnection, "SELECT * FROM users WHERE email = '{$email}'");
                if ($p_query) {
                    $user_info = pg_fetch_row($p_query);
                    $response = json_encode(array("success" => 'true', 'error' => '', 'result' => $user_info, 'user_id' => $_REQUEST['user_id']));
                    echo $_GET['callback'] . '(' . $response . ')';
                    exit;
                }
            } else {
                $response = json_encode(array("success" => 'false', 'error' => 'something went wrong while inserting.'));
                echo $_GET['callback'] . '(' . $response . ')';
                exit;
            }
        } else {
Example #16
0
<?php

//  Valor de retorno
//	0: usuario introdujo mal los datos
//	1: operacion realizada satisfactoriamente
//	2: hack
//	3: ya existe en la base de datos
if (isset($_POST['email'])) {
    $dbconn = pg_connect("host=localhost port=5432 dbname=univeonl_univeonl user=univeonl_univeonl password=admin") or die("No se pudo conectar a la Base de Datos");
    //echo "Conectado satisfactoriamente.\n";
    $email_from = $_POST['email'];
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}$/';
    if (!preg_match($email_exp, $email_from)) {
        echo "0";
    } else {
        $qu = pg_query($dbconn, "SELECT email FROM maillist WHERE email = '" . $_POST['email'] . "'");
        $rows = pg_num_rows($qu);
        if ($rows == 0) {
            $res = pg_insert($dbconn, 'maillist', $_POST);
            if ($res) {
                echo "1";
            }
        } else {
            echo "3";
        }
    }
    pg_close($dbconn);
} else {
    echo "2";
}
Example #17
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, 'phptests.foo', array('id' => 1, 'id2' => 2));
pg_update($conn, 'foo', array('id' => 10), array('id' => 1));
var_dump(pg_update($conn, 'foo', array('id' => 10), array('id' => 1), PGSQL_DML_STRING));
pg_update($conn, 'phptests.foo', array('id' => 100), array('id2' => 2));
var_dump(pg_update($conn, 'phptests.foo', array('id' => 100), array('id2' => 2), PGSQL_DML_STRING));
$rs = pg_query('SELECT * FROM foo UNION SELECT * FROM phptests.foo');
while ($row = pg_fetch_assoc($rs)) {
    var_dump($row);
}
pg_query('DROP TABLE foo');
pg_query('DROP TABLE phptests.foo');
pg_query('DROP SCHEMA phptests');
require 'bookdetails.php';
$result = getDetails($isbn);
$title = $result['title'];
$description = pg_escape_string($result['description']);
$publisher = $result['publisher'];
$query = "insert into books (isbn, title, publisher,description, by_user, ts) values ('{$isbn}', '{$title}',\n                                '{$publisher}', '{$description}', '{$username}', CURRENT_TIMESTAMP);";
$imagelink = $result['image-link'];
if ($title == null) {
    echo json_encode(array('result' => 'false'));
    return;
}
$content = file_get_contents($imagelink);
$fp = fopen("../books_pics/{$isbn}.jpg", "w");
fwrite($fp, $content);
fclose($fp);
$res1 = pg_query($query);
$done1 = $res1 ? true : false;
$done2 = false;
foreach ($result['authors'] as $value) {
    $done2 = false;
    $res2 = pg_insert($dbconn, "author", array('isbn' => $isbn, 'author' => $value));
    if (!$res2) {
        break;
    }
    $done2 = true;
}
if (done1 && done2) {
    echo json_encode(array('result' => 'true'));
} else {
    echo json_encode(array('result' => 'false'));
}
<?php

require 'db_conn.php';
$author_id = $_POST['author_id'];
$title = $_POST['title'];
$author_name = $_POST['author_name'];
$details = $_POST['details'];
$tags = $_POST['tags'];
$ftags = $_POST['faculty_tags'];
$logf = fopen('logfile.txt', 'w');
fwrite($logf, "{$author_id} {$title} {$author_name} {$details} {$tags} {$ftags}");
fclose($logf);
$query = "insert into question_forum (ts,asker, title, content ) values (CURRENT_TIMESTAMP,'{$author_id}','{$title}','{$details}'); select lastval();";
$result = pg_query($query);
$row = pg_fetch_array($result);
$row = $row[0];
foreach (explode(" ", $tags) as $value) {
    pg_insert($dbconn, "qtags", array('qid' => $row, 'htag' => $value));
}
foreach (explode(",", $ftags) as $value) {
    pg_insert($dbconn, "qtags", array('qid' => $row, 'htag' => $value));
}
echo json_encode(array('result' => "true"));
Example #20
-1
 public function insertArray($array)
 {
     foreach ($array as $arr) {
         pg_insert($this->conn, $this->table, $arr) or die("Ошибка внесения массива в таблицу " . $this->table . ": " . pg_last_error());
     }
     return true;
 }
Example #21
-1
 public function insertArray($array)
 {
     foreach ($array as $arr) {
         pg_insert($this->conn, $this->table, $arr) or die('[{"success":false, "message":"Ошибка внесения массива в таблицу ' . $this->table . '}]"');
     }
     return true;
 }