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


PHP pg_result_error_field函数代码示例

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


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

示例1: castResult

 public static function castResult($result, array $a, Stub $stub, $isNested)
 {
     $a['num rows'] = pg_num_rows($result);
     $a['status'] = pg_result_status($result);
     if (isset(self::$resultStatus[$a['status']])) {
         $a['status'] = new ConstStub(self::$resultStatus[$a['status']], $a['status']);
     }
     $a['command-completion tag'] = pg_result_status($result, PGSQL_STATUS_STRING);
     if (-1 === $a['num rows']) {
         foreach (self::$diagCodes as $k => $v) {
             $a['error'][$k] = pg_result_error_field($result, $v);
         }
     }
     $a['affected rows'] = pg_affected_rows($result);
     $a['last OID'] = pg_last_oid($result);
     $fields = pg_num_fields($result);
     for ($i = 0; $i < $fields; ++$i) {
         $field = array('name' => pg_field_name($result, $i), 'table' => sprintf('%s (OID: %s)', pg_field_table($result, $i), pg_field_table($result, $i, true)), 'type' => sprintf('%s (OID: %s)', pg_field_type($result, $i), pg_field_type_oid($result, $i)), 'nullable' => (bool) pg_field_is_null($result, $i), 'storage' => pg_field_size($result, $i) . ' bytes', 'display' => pg_field_prtlen($result, $i) . ' chars');
         if (' (OID: )' === $field['table']) {
             $field['table'] = null;
         }
         if ('-1 bytes' === $field['storage']) {
             $field['storage'] = 'variable size';
         } elseif ('1 bytes' === $field['storage']) {
             $field['storage'] = '1 byte';
         }
         if ('1 chars' === $field['display']) {
             $field['display'] = '1 char';
         }
         $a['fields'][] = new EnumStub($field);
     }
     return $a;
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:33,代码来源:PgSqlCaster.php

示例2: query

 /**
  * 执行数据库查询
  *
  * @param string $query 数据库查询SQL字符串
  * @param mixed $handle 连接对象
  * @param integer $op 数据库读写状态
  * @param string $action 数据库动作
  * @throws Typecho_Db_Exception
  * @return resource
  */
 public function query($query, $handle, $op = Typecho_Db::READ, $action = NULL)
 {
     $isQueryObject = $query instanceof Typecho_Db_Query;
     $this->_lastTable = $isQueryObject ? $query->getAttribute('table') : NULL;
     if ($resource = @pg_query($handle, $isQueryObject ? $query->__toString() : $query)) {
         return $resource;
     }
     /** 数据库异常 */
     throw new Typecho_Db_Query_Exception(@pg_last_error($this->_dbLink), pg_result_error_field(pg_get_result($this->_dbLink), PGSQL_DIAG_SQLSTATE));
 }
开发者ID:r0ker,项目名称:hctf2015-all-problems,代码行数:20,代码来源:Pgsql.php

示例3: 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

示例4: query

 public static function query($query)
 {
     try {
         $result = \pg_query(self::instance(), $query);
         if (!$result) {
             print_r(debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1));
         }
     } catch (\Exception $e) {
         throw new \Exception("not executed: " . $query);
     }
     $error = \pg_result_error_field($result, PGSQL_DIAG_SQLSTATE);
     if ($error) {
         throw new \Exception($error);
     }
     return new Result($result);
 }
开发者ID:yuzic,项目名称:aqua-framework,代码行数:16,代码来源:Connection.php

示例5: 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

示例6: ejecutarValidandoUniqueANDPrimaryKey

 function ejecutarValidandoUniqueANDPrimaryKey($sql)
 {
     if ($sql == "") {
         return 0;
     } else {
         /* Si puede enviar la consulta sin importar que encuentre llaves duplicadas */
         if (pg_send_query($this->connect, $sql)) {
             /* Ejecuta la consulta */
             $this->consulta_ID = pg_get_result($this->connect);
             /* Se tiene algun resultado sin importar que contenga errores de duplidados */
             if ($this->consulta_ID) {
                 /* Detecte un posible error */
                 $state = pg_result_error_field($this->consulta_ID, PGSQL_DIAG_SQLSTATE);
                 /* Si no se genero ningun error */
                 if ($state == 0) {
                     return $this->consulta_ID;
                 } else {
                     /* Si encontro algun error */
                     return false;
                 }
             }
         }
     }
 }
开发者ID:johnny9052,项目名称:loguinMasterPagePhpRegistroAjaxDAOPDF,代码行数:24,代码来源:clsConexion.php

示例7: error_number

 /**
  * Return an error number.
  *
  * @param resource $query
  * @return int The error number of the current error.
  */
 function error_number($query = null)
 {
     if ($query != null || !function_exists("pg_result_error_field")) {
         return 0;
     }
     return pg_result_error_field($query, PGSQL_DIAG_SQLSTATE);
 }
开发者ID:mainhan1804,项目名称:xomvanphong,代码行数:13,代码来源:db_pgsql.php

示例8: wpsql_errno

function wpsql_errno($connection)
{
    //		throw new Exception("Error Processing Request", 1);
    if ($connection == 1) {
        return false;
    }
    $result = pg_get_result($connection);
    $result_status = pg_result_status($result);
    return pg_result_error_field($result_status, PGSQL_DIAG_SQLSTATE);
}
开发者ID:gowrav-vishwakarma,项目名称:wp_clusterpoint,代码行数:10,代码来源:driver_clusterpoint_4.0.php

示例9: session_start

<?php

session_start();
include 'conexion.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $query = 'INSERT INTO tiposcontactos (id_tipocontacto, nombre, estado)' . " VALUES ((SELECT cargarRegistro('TiposContactos')),'" . $_POST['tipo_contacto'] . "', true)";
    conectarBD();
    if (pg_send_query($conexion, $query)) {
        $resultado = pg_get_result($conexion);
        if ($resultado) {
            $estado = pg_result_error_field($resultado, PGSQL_DIAG_SQLSTATE);
            if ($estado == 0) {
                // En caso de que no haya ningún error.
                $_SESSION['error_bd'] = false;
                $_SESSION['insert_successful'] = true;
                $_SESSION['success_msg'] = "Contacto agregado exitosamente.";
            } else {
                //Hay algún error.
                $_SESSION['error_bd'] = true;
                $_SESSION['estado'] = $estado;
                if ($estado == "23505") {
                    $_SESSION['estado'] = "Violación de valor único";
                    // Violación de estado único.
                }
            }
        } else {
            $_SESSION['error_bd'] = true;
            $_SESSION['estado'] = "Error Desconocido";
        }
        header('Location: mantenimientos.php');
    }
开发者ID:pornuestropais,项目名称:PHPCRM,代码行数:31,代码来源:do_agregar_tipocontacto.php

示例10: performQuery

 /**
  * @throws DBQueryException
  * @param ISqlQUery $query
  * @param boolean $isAsync
  * @return resource
  */
 protected function performQuery(ISqlQuery $query, $isAsync)
 {
     Assert::isBoolean($isAsync);
     $parameters = $query->getPlaceholderValues($this->getDialect());
     $queryAsString = $query->toDialectString($this->getDialect());
     if ($isAsync) {
         LoggerPool::log(parent::LOG_VERBOSE, 'sending an async query: %s', $queryAsString);
     } else {
         LoggerPool::log(parent::LOG_VERBOSE, 'sending query: %s', $queryAsString);
     }
     LoggerPool::log(parent::LOG_QUERY, $queryAsString);
     $executeResult = pg_send_query($this->link, $queryAsString);
     if (!$isAsync || !$executeResult) {
         $result = pg_get_result($this->link);
         $resultStatus = pg_result_status($result, PGSQL_STATUS_LONG);
         if (in_array($resultStatus, array(PGSQL_EMPTY_QUERY, PGSQL_BAD_RESPONSE, PGSQL_NONFATAL_ERROR, PGSQL_FATAL_ERROR))) {
             $errorCode = pg_result_error_field($result, PGSQL_DIAG_SQLSTATE);
             $errorMessage = pg_result_error_field($result, PGSQL_DIAG_MESSAGE_PRIMARY);
             if (PgSqlError::UNIQUE_VIOLATION == $errorCode) {
                 LoggerPool::log(parent::LOG_VERBOSE, 'query caused a unique violation: %s', $errorMessage);
                 throw new UniqueViolationException($query, $errorMessage);
             } else {
                 LoggerPool::log(parent::LOG_VERBOSE, 'query caused an error #%s: %s', $errorCode, $errorMessage);
                 throw new PgSqlQueryException($query, $errorMessage, $errorCode);
             }
         }
     }
     return $result;
 }
开发者ID:phoebius,项目名称:ajax-example,代码行数:35,代码来源:PgSqlDB.class.php

示例11: query

 private function query($query, $etypeDirty = null)
 {
     while (pg_get_result($this->link)) {
         // Clear the connection of all results.
         continue;
     }
     if (!pg_send_query($this->link, $query)) {
         throw new Exceptions\QueryFailedException('Query failed: ' . pg_last_error(), 0, null, $query);
     }
     if (!($result = pg_get_result($this->link))) {
         throw new Exceptions\QueryFailedException('Query failed: ' . pg_last_error(), 0, null, $query);
     }
     if ($error = pg_result_error_field($result, PGSQL_DIAG_SQLSTATE)) {
         // If the tables don't exist yet, create them.
         if ($error == '42P01' && $this->createTables()) {
             if (isset($etypeDirty)) {
                 $this->createTables($etypeDirty);
             }
             if (!($result = pg_query($this->link, $query))) {
                 throw new Exceptions\QueryFailedException('Query failed: ' . pg_last_error(), 0, null, $query);
             }
         } else {
             throw new Exceptions\QueryFailedException('Query failed: ' . pg_last_error(), 0, null, $query);
         }
     }
     return $result;
 }
开发者ID:sciactive,项目名称:nymph-server,代码行数:27,代码来源:PostgreSQLDriver.php

示例12: execute

 /**
  * Execute the SQL statement.
  *
  * @return  mixed  A database cursor resource on success, boolean false on failure.
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function execute()
 {
     $this->connect();
     // Take a local copy so that we don't modify the original query and cause issues later
     $sql = $this->replacePrefix((string) $this->sql);
     if ($this->limit > 0 || $this->offset > 0) {
         $sql .= ' LIMIT ' . $this->limit . ' OFFSET ' . $this->offset;
     }
     $count = $this->getCount();
     // Increment the query counter.
     $this->count++;
     // If debugging is enabled then let's log the query.
     if ($this->debug) {
         // Add the query to the object queue.
         $this->log(Log\LogLevel::DEBUG, '{sql}', array('sql' => $sql, 'category' => 'databasequery', 'trace' => debug_backtrace()));
     }
     // Reset the error values.
     $this->errorNum = 0;
     $this->errorMsg = '';
     // Bind the variables
     if ($this->sql instanceof PreparableInterface) {
         $bounded =& $this->sql->getBounded();
         if (count($bounded)) {
             // Execute the query. Error suppression is used here to prevent warnings/notices that the connection has been lost.
             $this->cursor = @pg_execute($this->connection, $this->queryName . $count, array_values($bounded));
         } else {
             // Execute the query. Error suppression is used here to prevent warnings/notices that the connection has been lost.
             $this->cursor = @pg_query($this->connection, $sql);
         }
     } else {
         // Execute the query. Error suppression is used here to prevent warnings/notices that the connection has been lost.
         $this->cursor = @pg_query($this->connection, $sql);
     }
     // If an error occurred handle it.
     if (!$this->cursor) {
         // Check if the server was disconnected.
         if (!$this->connected()) {
             try {
                 // Attempt to reconnect.
                 $this->connection = null;
                 $this->connect();
             } catch (ConnectionFailureException $e) {
                 // Get the error number and message.
                 $this->errorNum = (int) pg_result_error_field($this->cursor, PGSQL_DIAG_SQLSTATE) . ' ';
                 $this->errorMsg = pg_last_error($this->connection);
                 // Throw the normal query exception.
                 $this->log(Log\LogLevel::ERROR, 'Database query failed (error #{code}): {message}; Failed query: {sql}', array('code' => $this->errorNum, 'message' => $this->errorMsg, 'sql' => $sql));
                 throw new ExecutionFailureException($sql, $this->errorMsg);
             }
             // Since we were able to reconnect, run the query again.
             return $this->execute();
         } else {
             // Get the error number and message.
             $this->errorNum = (int) pg_result_error_field($this->cursor, PGSQL_DIAG_SQLSTATE) . ' ';
             $this->errorMsg = pg_last_error($this->connection) . "\nSQL={$sql}";
             // Throw the normal query exception.
             $this->log(Log\LogLevel::ERROR, 'Database query failed (error #{code}): {message}; Failed query: {sql}', array('code' => $this->errorNum, 'message' => $this->errorMsg, 'sql' => $sql));
             throw new ExecutionFailureException($sql, $this->errorMsg);
         }
     }
     return $this->cursor;
 }
开发者ID:jbanety,项目名称:database,代码行数:70,代码来源:PostgresqlDriver.php

示例13: wpsql_errno

function wpsql_errno($connection)
{
    $result = pg_get_result($connection);
    $result_status = pg_result_status($result);
    return pg_result_error_field($result_status, PGSQL_DIAG_SQLSTATE);
}
开发者ID:PulseSoftwareInc,项目名称:wordpress-heroku,代码行数:6,代码来源:driver_pgsql.php

示例14: dbError

 /**
  * Returns a database error message
  *
  * @param    string      $sql    SQL that may have caused the error
  * @return   string      Text for error message
  *
  */
 function dbError($sql = '')
 {
     $result = pg_get_result($this->_db);
     if ($this->_pgsql_version >= 7.4) {
         // this provides a much more detailed error report
         if (pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE)) {
             $this->_errorlog('You have an error in your SQL query on line ' . pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE) . "\nSQL in question: {$sql}");
             $this->_errorlog('Error: ' . pg_result_error_field($result, PGSQL_DIAG_SQLSTATE) . "\nDescription: " . pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL));
             if ($this->_display_error) {
                 $error = "An SQL error has occurred in the following SQL: {$sql}";
             } else {
                 $error = 'An SQL error has occurred. Please see error.log for details.';
             }
             return $error;
         }
     } else {
         if (pg_result_error($result)) {
             $this->_errorlog(pg_result_error($result) . ". SQL in question: {$sql}");
             if ($this->_display_error) {
                 $error = 'Error ' . pg_result_error($result);
             } else {
                 $error = 'An SQL error has occurred. Please see error.log for details.';
             }
             return $error;
         }
     }
     return;
 }
开发者ID:alxstuart,项目名称:ajfs.me,代码行数:35,代码来源:pgsql.class.php

示例15: execute

	/**
	 * Execute the SQL statement.
	 *
	 * @return  mixed  A database cursor resource on success, boolean false on failure.
	 *
	 * @since   12.1
	 * @throws  RuntimeException
	 */
	public function execute()
	{
		$this->connect();

		if (!is_resource($this->connection))
		{
			JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), JLog::ERROR, 'database');
			throw new RuntimeException($this->errorMsg, $this->errorNum);
		}

		// Take a local copy so that we don't modify the original query and cause issues later
		$sql = $this->replacePrefix((string) $this->sql);

		if ($this->limit > 0 || $this->offset > 0)
		{
			$sql .= ' LIMIT ' . $this->limit . ' OFFSET ' . $this->offset;
		}

		// Increment the query counter.
		$this->count++;

		// If debugging is enabled then let's log the query.
		if ($this->debug)
		{
			// Add the query to the object queue.
			$this->log[] = $sql;

			JLog::add($sql, JLog::DEBUG, 'databasequery');
		}

		// Reset the error values.
		$this->errorNum = 0;
		$this->errorMsg = '';

		// Execute the query. Error suppression is used here to prevent warnings/notices that the connection has been lost.
		$this->cursor = @pg_query($this->connection, $sql);

		// If an error occurred handle it.
		if (!$this->cursor)
		{
			// Check if the server was disconnected.
			if (!$this->connected())
			{
				try
				{
					// Attempt to reconnect.
					$this->connection = null;
					$this->connect();
				}
				// If connect fails, ignore that exception and throw the normal exception.
				catch (RuntimeException $e)
				{
					// Get the error number and message.
					$this->errorNum = (int) pg_result_error_field($this->cursor, PGSQL_DIAG_SQLSTATE) . ' ';
					$this->errorMsg = JText::_('JLIB_DATABASE_QUERY_FAILED') . "\n" . pg_last_error($this->connection) . "\nSQL=$sql";

					// Throw the normal query exception.
					JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), JLog::ERROR, 'databasequery');
					throw new RuntimeException($this->errorMsg);
				}

				// Since we were able to reconnect, run the query again.
				return $this->execute();
			}
			// The server was not disconnected.
			else
			{
				// Get the error number and message.
				$this->errorNum = (int) pg_result_error_field($this->cursor, PGSQL_DIAG_SQLSTATE) . ' ';
				$this->errorMsg = JText::_('JLIB_DATABASE_QUERY_FAILED') . "\n" . pg_last_error($this->connection) . "\nSQL=$sql";

				// Throw the normal query exception.
				JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), JLog::ERROR, 'databasequery');
				throw new RuntimeException($this->errorMsg);
			}
		}

		return $this->cursor;
	}
开发者ID:realityking,项目名称:joomla-platform,代码行数:87,代码来源:postgresql.php


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