当前位置: 首页>>代码示例>>PHP>>正文


PHP pg_result_error函数代码示例

本文整理汇总了PHP中pg_result_error函数的典型用法代码示例。如果您正苦于以下问题:PHP pg_result_error函数的具体用法?PHP pg_result_error怎么用?PHP pg_result_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pg_result_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: safe_dml_query

function safe_dml_query($query, $verbose = True)
{
    global $conn;
    if ($verbose) {
        echo "------------------------\n";
        echo "Executing PG query: {$query}\n";
    }
    $time_start = microtime(true);
    pg_send_query($conn, $query) or die("Failed to execute query {$query}");
    while (pg_connection_busy($conn)) {
        if (microtime(true) - $time_start > 30) {
            if (rand(0, 10) == 0) {
                echo "Busy for " . round((microtime(true) - $time_start) * 1000) . " ms -";
            }
            sleep(5);
        }
        usleep(2000);
    }
    $res = pg_get_result($conn);
    if (pg_result_error($res) != null) {
        die("Error during query: " . pg_result_error($res) . "\n");
    }
    $time_end = microtime(true);
    $rows = pg_affected_rows($res);
    if ($verbose) {
        echo "Done executing {$query}: {$rows} touched\n";
        $t = round(($time_end - $time_start) * 1000);
        echo "Query time: {$t} ms\n";
        echo "------------------------\n";
    }
}
开发者ID:johnpyeatt,项目名称:nominatiny,代码行数:31,代码来源:dbutils.inc.php

示例2: __construct

 public function __construct($result, $sql, $as_object = FALSE, $params = NULL, $total_rows = NULL)
 {
     parent::__construct($result, $sql, $as_object, $params);
     if ($as_object === TRUE) {
         $this->_as_object = 'stdClass';
     }
     if ($total_rows !== NULL) {
         $this->_total_rows = $total_rows;
     } else {
         switch (pg_result_status($result)) {
             case PGSQL_TUPLES_OK:
                 $this->_total_rows = pg_num_rows($result);
                 break;
             case PGSQL_COMMAND_OK:
                 $this->_total_rows = pg_affected_rows($result);
                 break;
             case PGSQL_BAD_RESPONSE:
             case PGSQL_NONFATAL_ERROR:
             case PGSQL_FATAL_ERROR:
                 throw new Database_Exception(':error [ :query ]', array(':error' => pg_result_error($result), ':query' => $sql));
             case PGSQL_COPY_OUT:
             case PGSQL_COPY_IN:
                 throw new Database_Exception('PostgreSQL COPY operations not supported [ :query ]', array(':query' => $sql));
             default:
                 $this->_total_rows = 0;
         }
     }
 }
开发者ID:alekseyshavrak,项目名称:3cx,代码行数:28,代码来源:Result.php

示例3: query

 public function query($sql)
 {
     $resource = pg_query($this->link, $sql);
     if ($resource) {
         if (is_resource($resource)) {
             $i = 0;
             $data = array();
             while ($result = pg_fetch_assoc($resource)) {
                 $data[$i] = $result;
                 $i++;
             }
             pg_free_result($resource);
             $query = new \stdClass();
             $query->row = isset($data[0]) ? $data[0] : array();
             $query->rows = $data;
             $query->num_rows = $i;
             unset($data);
             return $query;
         } else {
             return true;
         }
     } else {
         trigger_error('Error: ' . pg_result_error($this->link) . '<br />' . $sql);
         exit;
     }
 }
开发者ID:Andreyalex,项目名称:corsica,代码行数:26,代码来源:postgre.php

示例4: __construct

 /**
  * @param   resource    from pg_query() or pg_get_result()
  * @param   string      SQL used to create this result
  * @param   resource    from pg_connect() or pg_pconnect()
  * @param   boolean|string
  * @return  void
  */
 public function __construct($result, $sql, $link, $return_objects)
 {
     // PGSQL_COMMAND_OK     <- SET client_encoding = 'utf8'
     // PGSQL_TUPLES_OK      <- SELECT table_name FROM information_schema.tables
     // PGSQL_COMMAND_OK     <- INSERT INTO pages (name) VALUES ('gone soon')
     // PGSQL_COMMAND_OK     <- DELETE FROM pages WHERE id = 2
     // PGSQL_COMMAND_OK     <- UPDATE pb_users SET company_id = 1
     // PGSQL_FATAL_ERROR    <- SELECT FROM pages
     switch (pg_result_status($result)) {
         case PGSQL_EMPTY_QUERY:
             $this->total_rows = 0;
             break;
         case PGSQL_COMMAND_OK:
             $this->total_rows = pg_affected_rows($result);
             break;
         case PGSQL_TUPLES_OK:
             $this->total_rows = pg_num_rows($result);
             break;
         case PGSQL_COPY_OUT:
         case PGSQL_COPY_IN:
             Kohana_Log::add('debug', 'PostgreSQL COPY operations not supported');
             break;
         case PGSQL_BAD_RESPONSE:
         case PGSQL_NONFATAL_ERROR:
         case PGSQL_FATAL_ERROR:
             throw new Database_Exception(':error [ :query ]', array(':error' => pg_result_error($result), ':query' => $sql));
     }
     $this->link = $link;
     $this->result = $result;
     $this->return_objects = $return_objects;
     $this->sql = $sql;
 }
开发者ID:anqqa,项目名称:Anqh,代码行数:39,代码来源:Database_Postgresql_Result.php

示例5: conn_db

 public static function conn_db($dbdata)
 {
     if (is_array($dbdata)) {
         extract($dbdata[Db::$dbconn]);
         Db::$db = @$dbtype;
     }
     $error = '';
     switch (Db::$db) {
         case 'Pg':
             $con = pg_connect("host={$host} port={$port} dbname={$database} user={$user} password={$password}") or die("{$error}=" . pg_result_error());
             break;
         case 'Mysql':
             $con = mysql_connect($host . ':' . $port, $user, $password);
             mysql_select_db($database) or die("{$error}=" . mysql_error());
             break;
         case 'Oci':
             $con = oci_connect($user, $password, $host . ':' . $port . '/' . $database);
             if (!$con) {
                 $error = oci_error();
                 trigger_error(htmlentities($error['message'], ENT_QUOTES), E_USER_ERROR);
             }
             break;
     }
     if ($error != '') {
         $con = $error;
     }
     return $con;
 }
开发者ID:hezrul,项目名称:seashell,代码行数:28,代码来源:class.db.php

示例6: sendQuery

 /**
  * Method to send SQL query
  *
  * @param   resource    $res_conn
  * @return  void
  */
 private function sendQuery($res_conn)
 {
     // checking query type
     // if the query return recordset or not
     if (preg_match("/^(SELECT)\\s/i", $this->sql_string)) {
         $this->res_result = @pg_query($res_conn, $this->sql_string);
         // error checking
         if (!$this->res_result) {
             $this->errno = 1;
             $this->error = "Query failed to executed. Please check your query again. \n" . pg_result_error($this->res_result);
         } else {
             // count number of rows
             $this->num_rows = @pg_num_rows($this->res_result);
         }
     } else {
         $_query = @pg_query($res_conn, $this->sql_string);
         // error checking
         if (!$_query) {
             $this->errno = 1;
             $this->error = "Query failed to executed. Please check your query again. \n" . pg_last_error($res_conn);
         } else {
             // get number of affected row
             $this->affected_rows = @pg_affected_rows($_query);
             // get last OID if it is insert operation
             if (preg_match("/^(INSERT)\\s/i", $this->sql_string)) {
                 $this->insert_id = @pg_last_oid($_query);
             }
         }
         // nullify query
         $_query = null;
     }
 }
开发者ID:banumelody,项目名称:slims7_cendana,代码行数:38,代码来源:simbio_pgsql_result.inc.php

示例7: getRecordCount

 /**
  * @see ResultSet::getRecordCount()
  */
 public function getRecordCount()
 {
     $rows = @pg_num_rows($this->result);
     if ($rows === null) {
         throw new SQLException("Error fetching num rows", pg_result_error($this->result));
     }
     return (int) $rows;
 }
开发者ID:BackupTheBerlios,项目名称:nodin-svn,代码行数:11,代码来源:PgSQLResultSet.php

示例8: dbLastInsertId

function dbLastInsertId()
{
    global $database_connection;
    $result = pg_query($database_connection, "SELECT lastval();");
    if (!$result) {
        die("PG Error: " . pg_result_error($result));
    }
    $row = pg_fetch_row($result);
    return $row[0];
}
开发者ID:qualitysmith,项目名称:qs_basic_affiliate,代码行数:10,代码来源:database.php

示例9: login

function login()
{
    $schema = "feedmati_system";
    $conn = dbconnect();
    $user = $_POST['username'];
    $loginQuery = "SELECT * FROM {$GLOBALS['schema']}.authentication WHERE user_email = \$1";
    $stmt = pg_prepare($conn, "login", $loginQuery);
    echo pg_result_error($stmt);
    if (!$stmt) {
        echo "Error, can't prepare login query<br>";
        return;
    }
    $result = pg_execute($conn, "login", array($user));
    if (pg_num_rows($result) == 0) {
        echo "Username or Password is incorrect";
        return;
    }
    $saltQuery = "SELECT salt FROM {$GLOBALS['schema']}.authentication WHERE user_email = \$1";
    $saltPrepare = pg_prepare($conn, "salt", $saltQuery);
    if (!$saltPrepare) {
        echo "Could not sanitize query for salt";
        return;
    }
    $saltResult = pg_execute($conn, "salt", array($user));
    if (pg_num_rows($saltResult) > 0) {
        $saltRow = pg_fetch_assoc($saltResult);
        $salt = $saltRow['salt'];
        $salt = trim($salt);
        $saltedpw = sha1($_POST['password'] . $salt);
    }
    $userPassPrepare = pg_prepare($conn, "pwquery", "SELECT * FROM {$GLOBALS['schema']}.authentication WHERE user_email = \$1 AND password_hash = \$2");
    if (!$userPassPrepare) {
        echo "Error, can't prepare username password query<br>";
    }
    $user = $_POST['username'];
    $pwq = array($user, $saltedpw);
    $userPassResult = pg_execute($conn, "pwquery", $pwq);
    $numrows = pg_num_rows($userPassResult);
    //if there is a match it logs the person in and adds an entry to the log
    if ($numrows == 1) {
        $action = "login";
        $_SESSION['user'] = $user;
        $userPassRow = pg_fetch_assoc($userPassResult);
        $fname = $userPassRow['fname'];
        $_SESSION['fname'] = $fname;
        header("Location: home.php");
    } else {
        echo "Username or Password is incorrect";
    }
    pg_close($conn);
}
开发者ID:tanliuyuan,项目名称:FeedmationWebsite,代码行数:51,代码来源:loginFunctions.php

示例10: rawQuery

 public function rawQuery($sql, array $params = [])
 {
     if (empty($params)) {
         pg_send_query($this->dbconn, $sql);
     } else {
         pg_send_query_params($this->dbconn, $sql, $params);
     }
     $result = pg_get_result($this->dbconn);
     $err = pg_result_error($result);
     if ($err) {
         throw new \Pg\Exception($err, 0, null, pg_result_error_field($result, PGSQL_DIAG_SQLSTATE));
     }
     return new \Pg\Statement($result, $this->typeConverter);
 }
开发者ID:aoyagikouhei,项目名称:pg,代码行数:14,代码来源:Db.php

示例11: __construct

 /**
  * @param resource $handle PostgreSQL result resource.
  */
 public function __construct($handle)
 {
     $this->handle = $handle;
     parent::__construct(function (callable $emit) {
         $count = \pg_num_rows($this->handle);
         for ($i = 0; $i < $count; ++$i) {
             $result = \pg_fetch_assoc($this->handle);
             if (false === $result) {
                 throw new FailureException(\pg_result_error($this->handle));
             }
             yield from $emit($result);
         }
         return $i;
     });
 }
开发者ID:icicleio,项目名称:postgres,代码行数:18,代码来源:TupleResult.php

示例12: query_execute

function query_execute($query, $params = false)
{
    if ($params) {
        list($query_prepped, $params_array) = __query_prep_params($query, $params);
        $result = pg_query_params($query_prepped, $params_array);
    } else {
        $result = pg_query($query);
    }
    if ($result) {
        return $result;
    } else {
        error_log(pg_result_error($result));
        return false;
    }
}
开发者ID:eon8ight,项目名称:under-the-couch,代码行数:15,代码来源:db_lib.php

示例13: query

 function query($sql)
 {
     @pg_send_query($this->link_id, $sql);
     $this->query_result = @pg_get_result($this->link_id);
     if (pg_result_status($this->query_result) != PGSQL_FATAL_ERROR) {
         ++$this->num_queries;
         //$this->last_query_text[$this->query_result] = $sql;
         return $this->query_result;
     } else {
         if ($this->in_transaction) {
             @pg_query($this->link_id, 'ROLLBACK');
         }
         --$this->in_transaction;
         die(error(pg_result_error($this->query_result)));
         return false;
     }
 }
开发者ID:scamp,项目名称:minimanager,代码行数:17,代码来源:pgsql.php

示例14: query

 public function query($query)
 {
     if (!pg_send_query($this->connection, $query)) {
         throw $this->createException(pg_last_error($this->connection), 0, NULL);
     }
     $time = microtime(TRUE);
     $resource = pg_get_result($this->connection);
     $time = microtime(TRUE) - $time;
     if ($resource === FALSE) {
         throw $this->createException(pg_last_error($this->connection), 0, NULL);
     }
     $state = pg_result_error_field($resource, PGSQL_DIAG_SQLSTATE);
     if ($state !== NULL) {
         throw $this->createException(pg_result_error($resource), 0, $state, $query);
     }
     $this->affectedRows = pg_affected_rows($resource);
     return new Result(new PgsqlResultAdapter($resource), $this, $time);
 }
开发者ID:jasir,项目名称:dbal,代码行数:18,代码来源:PgsqlDriver.php

示例15: execute

 public function execute($sql)
 {
     // hide errors
     $ini_err = ini_get('display_errors');
     ini_set('display_errors', 0);
     $res = false;
     $this->res_errMsg = null;
     // --- process sql
     if ($this->dbType == 'postgres') {
         $this->res_data = pg_query($this->dbConn, $sql);
         if (!$this->res_data) {
             $this->res_errMsg = pg_last_error($this->dbConn);
         } else {
             $this->res_errMsg = pg_result_error($this->res_data);
             $this->res_affectedRows = pg_affected_rows($this->res_data);
             $this->res_rowCount = pg_num_rows($this->res_data);
             $this->res_fieldCount = pg_num_fields($this->res_data);
             $res = new dbRecordSet($this->dbType, $this->res_data, $this->res_rowCount, $this->res_fieldCount);
             // -- parse field names
             for ($i = 0; $i < $this->res_fieldCount; $i++) {
                 $this->res_fields[$i] = pg_field_name($this->res_data, $i);
                 $this->res_fieldsInfo[$i] = array();
                 $this->res_fieldsInfo[$i]['type'] = pg_field_type($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['len'] = pg_field_size($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['is_null'] = pg_field_is_null($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['prt_len'] = pg_field_prtlen($this->res_data, $i);
             }
         }
         // log error
         if ($this->res_errMsg != '') {
             // put here code to log error
         }
     }
     // --- mysql
     if ($this->dbType == 'mysql') {
         $this->res_data = mysql_query($sql, $this->dbConn);
         if (!$this->res_data) {
             $this->res_errMsg = mysql_error($this->dbConn);
         } else {
             @($this->res_errMsg = mysql_error($this->res_data));
             @($this->res_affectedRows = mysql_affected_rows($this->res_data));
             @($this->res_rowCount = mysql_num_rows($this->res_data));
             @($this->res_fieldCount = mysql_num_fields($this->res_data));
             @($res = new dbRecordSet($this->dbType, $this->res_data, $this->res_rowCount, $this->res_fieldCount));
             // -- parse field names
             for ($i = 0; $i < $this->res_fieldCount; $i++) {
                 $this->res_fields[$i] = mysql_field_name($this->res_data, $i);
                 $this->res_fieldsInfo[$i] = array();
                 $this->res_fieldsInfo[$i]['type'] = mysql_field_type($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['len'] = mysql_field_len($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['flags'] = mysql_field_flags($this->res_data, $i);
             }
         }
         // log error
         if ($this->res_errMsg != '') {
             // put here code to log error
         }
     }
     $this->res_sql = $sql;
     // show debug info if on
     if ($this->debug == true) {
         print "<pre>" . $sql . "<hr>";
         if ($this->res_errMsg != '') {
             print "<span style='color: red'>" . $this->res_errMsg . "</span><hr>";
         }
         print "</pre>";
     }
     // restore errors
     ini_set('display_errors', $ini_err);
     return $res;
 }
开发者ID:LeisureLeo,项目名称:w2ui,代码行数:71,代码来源:w2db.php


注:本文中的pg_result_error函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。