當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PDOStatement::errorInfo方法代碼示例

本文整理匯總了PHP中PDOStatement::errorInfo方法的典型用法代碼示例。如果您正苦於以下問題:PHP PDOStatement::errorInfo方法的具體用法?PHP PDOStatement::errorInfo怎麽用?PHP PDOStatement::errorInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PDOStatement的用法示例。


在下文中一共展示了PDOStatement::errorInfo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: error

 /**
  * Return an array of error information about the last
  * performed operation.
  *
  * @param   bool    Value determines if the errorInfo should
  *                  be performed on the database handle or
  *                  the statement handle.
  * @return  array
  */
 public function error($connection = TRUE)
 {
     if ($connection) {
         return $this->connection->errorInfo();
     }
     return $this->statement->errorInfo();
 }
開發者ID:pkrll,項目名稱:Philotes,代碼行數:16,代碼來源:Database.php

示例2: handlePdoError

 /**
  * Handles PDO error by either printing it to the screen with other useful information (dev mode)
  * or logging the error
  * 
  * @param PDOStatement $stmt
  */
 protected function handlePdoError(\PDOStatement $stmt)
 {
     if ($this->mode == 'dev') {
         print_r($stmt->errorInfo());
     } else {
         if ($this->mode == 'prod') {
             error_log(implode(' - ', $stmt->errorInfo()));
         }
     }
 }
開發者ID:bashedev,項目名稱:Db,代碼行數:16,代碼來源:Db.php

示例3: executeQuery

 /**
  * Executes a query using current database connection
  *
  * @param $query
  * @return Tx_PtExtlist_Domain_DataBackend_DataSource_MySqlDataSource
  * @throws Exception
  */
 public function executeQuery($query)
 {
     try {
         /* @var $statement PDOStatement */
         $this->startTimeMeasure();
         $this->statement = $this->connection->prepare($query);
         $this->statement->execute();
         $this->stopTimeMeasure();
     } catch (Exception $e) {
         throw new Exception('Error while trying to execute query on database! SQL-Statement: ' . $query . ' - Error message from PDO: ' . $e->getMessage() . '. Further information from PDO_errorInfo: ' . $this->statement->errorInfo(), 1280322659);
     }
     return $this;
 }
開發者ID:punktde,項目名稱:pt_extlist,代碼行數:20,代碼來源:MySqlDataSource.php

示例4: query

 /**
  * Run a query against a database.  Get a result
  * @param string $query The SQL to run against the database
  * @param array $args An associative array of query parameters
  * @return bool|\PDOStatement False if query fails, results in this database's fetch_class if successful
  * @throws \Exception
  */
 public function query($query, $args = array())
 {
     if (!empty($this->pdo_statement)) {
         $this->pdo_statement->closeCursor();
     }
     if ($this->pdo_statement = $this->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true))) {
         $this->pdo_statement->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, $this->fetch_class, [$this]);
         if (!$this->pdo_statement->execute($args)) {
             throw new \Exception($this->pdo_statement->errorInfo());
         }
         return true;
     } else {
         throw new \Exception($this->errorInfo());
     }
 }
開發者ID:ringmaster,項目名稱:microsite2,代碼行數:22,代碼來源:DB.php

示例5: deleteRecord

 /**
  * {@inheritDoc}
  * @see \vxPHP\Database\DatabaseInterface::deleteRecord()
  * 
  * @throws \PDOException
  */
 public function deleteRecord($tableName, $keyValue)
 {
     if (!is_array($keyValue)) {
         if (!array_key_exists($tableName, $this->tableStructureCache) || empty($this->tableStructureCache[$tableName])) {
             $this->fillTableStructureCache($tableName);
         }
         if (!array_key_exists($tableName, $this->tableStructureCache)) {
             throw new \PDOException(sprintf("Table '%s' not found.", $tableName));
         }
         if (count($this->tableStructureCache[$tableName]['_primaryKeyColumns']) === 1) {
             $this->statement = $this->connection->prepare(sprintf("\n\t\t\t\t\t\t\tDELETE FROM\n\t\t\t\t\t\t\t\t%s\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t%s%s%s = ?\n\t\t\t\t\t\t", $tableName, self::QUOTE_CHAR, $this->tableStructureCache[$tableName]['_primaryKeyColumns'][0], self::QUOTE_CHAR));
             $this->statement->execute((array) $keyValue);
             return $this->statement->rowCount();
         } else {
             throw new \PDOException(sprintf("Table '%s' has more than one or no primary key column.", $tableName));
         }
     } else {
         $fieldNames = [];
         foreach (array_keys($keyValue) as $fieldName) {
             $fieldNames[] = self::QUOTE_CHAR . $fieldName . self::QUOTE_CHAR . ' = ?';
         }
         $this->statement = $this->connection->prepare(sprintf("\n\t\t\t\t\t\tDELETE FROM\n\t\t\t\t\t\t\t%s\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t%s\n\t\t\t\t\t", $tableName, implode(' AND ', $fieldNames)));
         if ($this->statement->execute(array_values($keyValue))) {
             return $this->statement->rowCount();
         }
         throw new \PDOException(vsprintf('ERROR: %s, %s, %s', $this->statement->errorInfo()));
     }
 }
開發者ID:vectrex,項目名稱:vxphp,代碼行數:34,代碼來源:Mysql.php

示例6: execute

	/**
	 * Executes the request against a PDO object
	 * 
	 * @return 	bool|Atomik_Db_Query_Result		False if fail or the Atomik_Db_Query_Result object
	 */
	public function execute($reCache = false, Atomik_Db_Query_Result $resultObject = null)
	{
		if ($this->_instance === null) {
			require_once 'Atomik/Db/Query/Exception.php';
			throw new Atomik_Db_Query_Exception('An Atomik_Db_Instance must be attached to the queyr to execute it');
		}
		
		if (($resultObject === null || !$reCache) && $this->_cachedResult !== null) {
			return $this->_cachedResult;
		}
		
		if ($this->_statement === null) {
			// prepare the query only if the statement is not already prepared
			$this->_statement = $this->_pdo->prepare($this->toSql());
		}
		
		$this->_lastError = false;
		if (!$this->_statement->execute($this->getParams())) {
			$this->_lastError = $this->_statement->errorInfo();
			return false;
		}
		
		if ($resultObject === null) {
			$resultObject = new Atomik_Db_Query_Result($this);
			if ($this->_cacheable) {
				$this->_cachedResult = $resultObject;
			}
		}
		
		$resultObject->reset($this->_statement);
		return $resultObject;
	}
開發者ID:neronen,項目名稱:tsoha-k11p4-atomik,代碼行數:37,代碼來源:Query.php

示例7: InternalException

 static function check_errors(PDOStatement $query)
 {
     $status = $query->errorInfo();
     if ($status[0] != 0) {
         throw new InternalException($status[2]);
     }
 }
開發者ID:jlsa,項目名稱:justitia,代碼行數:7,代碼來源:DB.php

示例8: execute

 /**
  * PDOSatement執行prepare,在失敗時會重試
  * @param array $params 執行參數
  * @param array $retryTimes 重試次數
  * @return 成功時返回 TRUE , 或者在失敗時返回 FALSE
  */
 public function execute($params = array(), $retryTimes = 3)
 {
     $res = $this->pdoStatement->execute($params);
     if ($res !== FALSE) {
         return $res;
     }
     // 這麽寫的原因是:如果第一次成功,就不需要while循環結構了,比起全部寫在while循環裏,效率要高很多
     // 如果第一次查詢失敗,則重試3次
     $retry = 0;
     while ($retry < $retryTimes) {
         $errInfo = $this->pdoStatement->errorInfo();
         if (is_array($errInfo) && $errInfo[0] == 'HY000' && $errInfo[1] == '2006') {
             // Mysql gone away
             if (!$this->reconnPdo()) {
                 return FALSE;
             }
         } else {
             // 甩出錯誤
             // throw new Error
             return FALSE;
             // 其他錯誤不重試,返回失敗
         }
         $this->pdoStatement = $this->pdo->prepare($this->sql);
         $res = $this->pdoStatement->execute($params);
         if ($res !== FALSE) {
             return $res;
         }
         $retry++;
     }
     return FALSE;
     // 最終返回FALSE
 }
開發者ID:seepre,項目名稱:api.seepre.com,代碼行數:38,代碼來源:MysqlPDOModel.php

示例9: execute

 public function execute($input_parameters = NULL)
 {
     if (APF::get_instance()->is_debug_enabled()) {
         APF::get_instance()->debug(__CLASS__ . '[' . $this->pdo->config['dsn'] . '|' . $this->pdo->get_name() . ']' . "->execute: " . $this->queryString);
     }
     $logger = APF::get_instance()->get_logger();
     $logger->debug(__CLASS__, '[' . $this->pdo->get_name() . ']->execute: ', $this->queryString);
     APF::get_instance()->pf_benchmark_inc_begin('dbtime');
     $start = microtime(true);
     $ret = parent::execute($input_parameters);
     $end = microtime(true);
     APF::get_instance()->pf_benchmark_inc_end('dbtime');
     //add by hexin for record SQL execute time
     APF::get_instance()->pf_benchmark("sql_time", array($this->i => $end - $start));
     // 按照慣用格式記錄sql執行時間和占用內存
     // added by htlv
     $tmp_time = $end - $start;
     $tmp_mem = memory_get_usage();
     apf_require_class('APF_Performance');
     APF::get_instance()->pf_benchmark("sql_time_af", array($this->i => array('sql' => $this->_sql, APF_Performance::MESSAGE_TIME => $tmp_time, APF_Performance::MESSAGE_MEMORY => $tmp_mem)));
     if (!$ret) {
         $error_info = parent::errorInfo();
         /**
          * remove duplicated error log
         $logger->error(__CLASS__, '['. $this->pdo->get_name() .']->execute: ', $this->queryString);
         $_error_info = preg_replace("#[\r\n \t]+#",' ',print_r($error_info,true));
         $logger->error(__CLASS__, '['. $this->pdo->get_name() .']->execute: ', $_error_info);
         */
         if (parent::errorCode() !== '00000') {
             throw new APF_Exception_SqlException($this->pdo->get_name() . ' | ' . $this->pdo->config['dsn'] . ' | ' . $this->queryString . ' | ' . join(' | ', $error_info), parent::errorCode());
         }
     }
     return $ret;
 }
開發者ID:emilymwang8,項目名稱:cms,代碼行數:34,代碼來源:PDOStatement.php

示例10: errorInfo

 public function errorInfo()
 {
     if ($this->_statement instanceof \PDOStatement) {
         return $this->_statement->errorInfo();
     }
     return null;
 }
開發者ID:rtshome,項目名稱:pgbabylon,代碼行數:7,代碼來源:PDOStatement.php

示例11: execute

 public function execute($input_parameters = NULL)
 {
     if (APF::get_instance()->is_debug_enabled()) {
         APF::get_instance()->debug(__CLASS__ . '[' . $this->pdo->config['dsn'] . '|' . $this->pdo->get_name() . ']' . "->execute: " . $this->queryString);
     }
     $logger = APF::get_instance()->get_logger();
     $logger->debug(__CLASS__, '[' . $this->pdo->get_name() . ']->execute: ', $this->queryString);
     APF::get_instance()->pf_benchmark_inc_begin('dbtime');
     $start = microtime(true);
     $ret = parent::execute($input_parameters);
     $end = microtime(true);
     APF::get_instance()->pf_benchmark_inc_end('dbtime');
     //add by hexin for record SQL execute time
     APF::get_instance()->pf_benchmark("sql_time", array($this->i => $end - $start));
     if (!$ret) {
         $error_info = parent::errorInfo();
         $logger->error(__CLASS__, '[' . $this->pdo->get_name() . ']->execute: ', $this->queryString);
         $_error_info = preg_replace("#[\r\n \t]+#", ' ', print_r($error_info, true));
         $logger->error(__CLASS__, '[' . $this->pdo->get_name() . ']->execute: ', $_error_info);
         if (parent::errorCode() !== '00000') {
             trigger_error($this->queryString . ' | ' . join(' | ', $error_info), E_USER_ERROR);
         }
     }
     return $ret;
 }
開發者ID:rh20083907,項目名稱:ipublish,代碼行數:25,代碼來源:PDOStatement.php

示例12: error

 /**
  * Return an array of error information about the last
  * performed operation.
  *
  * @param   bool    Value determines if the errorInfo should
  *                  be performed on the database handle or
  *                  the statement handle.
  * @return  array
  */
 public function error($connection = true)
 {
     if ($connection) {
         return array("error" => $this->connection->errorInfo());
     }
     return array("error" => $this->statement->errorInfo());
 }
開發者ID:pkrll,項目名稱:Database,代碼行數:16,代碼來源:Database.php

示例13: __construct

 public function __construct($message, PDOStatement $statement)
 {
     $infos = array();
     foreach ($statement->errorInfo() as $key => $info) {
         $infos[] = $key . ': ' . $info;
     }
     parent::__construct($message . '. (ERRNO ' . $statement->errorCode() . ') ' . implode('<br />', $infos));
 }
開發者ID:AroundPBT,項目名稱:PHPBoost,代碼行數:8,代碼來源:PDOQuerierException.class.php

示例14: getErrorDesc

	/**
	 * Returns the description of the last error.
	 * 
	 * @return	string
	 */
	public function getErrorDesc() {
		if ($this->pdoStatement !== null) {
			$errorInfoArray = $this->pdoStatement->errorInfo();
			if (isset($errorInfoArray[2])) return $errorInfoArray[2];
		}
		
		return '';
	}
開發者ID:0xLeon,項目名稱:WCF,代碼行數:13,代碼來源:PreparedStatement.class.php

示例15: execute

 /**
  * Tries to execute a statement, throw an explicit exception on failure
  */
 protected function execute(\PDOStatement $query, array $variables = array())
 {
     if (!$query->execute($variables)) {
         $errors = $query->errorInfo();
         throw new ModelException($errors[2]);
     }
     return $query;
 }
開發者ID:JulietteR,項目名稱:PHP_TD5,代碼行數:11,代碼來源:Model.php


注:本文中的PDOStatement::errorInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。