Example #1
0
 /**
  * sendPrepareQuery
  *
  * Send a prepare query statement to the server.
  *
  * @access public
  * @param  string     $identifier
  * @param  string     $sql
  * @return Connection $this
  */
 public function sendPrepareQuery($identifier, $sql)
 {
     $this->testQuery(pg_send_prepare($this->getHandler(), $identifier, $sql), sprintf("Could not send prepare statement «%s».", $sql))->getQueryResult(sprintf("PREPARE ===\n%s\n ===", $sql));
     return $this;
 }
Example #2
0
 }
 for ($i = 0; $i < $rows; $i++) {
     pg_fetch_row($result, $i);
 }
 for ($i = 0; $i < $rows; $i++) {
     pg_fetch_result($result, $i, 0);
 }
 pg_num_rows(pg_query_params($db, "SELECT * FROM " . $table_name . " WHERE num > \$1;", array(100)));
 pg_num_fields(pg_query_params($db, "SELECT * FROM " . $table_name . " WHERE num > \$1;", array(100)));
 pg_field_name($result, 0);
 pg_field_num($result, $field_name);
 pg_field_size($result, 0);
 pg_field_type($result, 0);
 pg_field_prtlen($result, 0);
 pg_field_is_null($result, 0);
 if (!pg_send_prepare($db, "php_test2", "INSERT INTO " . $table_name . " VALUES (\$1, \$2);")) {
     echo "pg_send_prepare() error\n";
 }
 while (pg_connection_busy($db)) {
 }
 // busy wait: intended
 if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
     echo "pg_connection_status() error\n";
 }
 if (!($result = pg_get_result($db))) {
     echo "pg_get_result() error\n";
 }
 pg_free_result($result);
 if (!pg_send_execute($db, "php_test2", array(9999, "A'BC"))) {
     echo "pg_send_execute() error\n";
 }
Example #3
0
 /**
  * prepare a statement and send it to the database
  *
  * @param string $qs
  * @param string $stmt_name
  * @uses self::error_string()
  * @return bool true | false
  */
 public function prepare($qs, $stmt_name)
 {
     try {
         if (!@pg_connection_busy($this->dbh)) {
             try {
                 if (!@pg_send_prepare($this->dbh, $stmt_name, $qs)) {
                     throw new Exception('prepare(): send_prepare failed');
                 }
                 if (!@pg_get_result($this->dbh)) {
                     throw new Exception('prepare(): get_result failed');
                 }
             } catch (Exception $e) {
                 throw $e;
             }
         } else {
             throw new Exception('prepare(): connection busy ');
         }
     } catch (Exception $e) {
         self::error_string($e);
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * Prepare a query asynchronously
  *
  * @param string $statementName
  * @param string $query
  * @return \Amp\Promise
  */
 public function prepare(string $statementName, string $query) : \Amp\Promise
 {
     if ($this->queryCacheSize > $this->maxOutstandingQueries) {
         return new \Amp\Failure(new \RuntimeException("Too busy"));
     }
     $deferred = new \Amp\Deferred();
     $this->queryCache[] = [self::$OP_QUERY_PARAMS, [$statementName, $query], $deferred];
     if (!$this->queryCacheSize++) {
         $sendResult = \pg_send_prepare($this->db, $statementName, $query);
         $this->processSendResult($sendResult);
     }
     return $deferred->promise();
 }