本文整理匯總了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();
}
示例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()));
}
}
}
示例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;
}
示例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());
}
}
示例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()));
}
}
示例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;
}
示例7: InternalException
static function check_errors(PDOStatement $query)
{
$status = $query->errorInfo();
if ($status[0] != 0) {
throw new InternalException($status[2]);
}
}
示例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
}
示例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;
}
示例10: errorInfo
public function errorInfo()
{
if ($this->_statement instanceof \PDOStatement) {
return $this->_statement->errorInfo();
}
return null;
}
示例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;
}
示例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());
}
示例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));
}
示例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 '';
}
示例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;
}