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


PHP PDOException::getCode方法代碼示例

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


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

示例1: handleError

 public function handleError($model, $query, \PDOException $e)
 {
     // echo "*** Model in handleError: " . $model . "\n";
     switch ($e->getCode()) {
         // MySQL table missing
         case '42S02':
             // SQLite table missing
         // SQLite table missing
         case 'HY000' && stripos($e->getMessage(), "no such table") !== false:
             if ($model != 'StdClass') {
                 $instance = new $model();
                 if ($instance instanceof ActiveRecord) {
                     $table_builder = new TableBuilder($instance);
                     $table_builder->build();
                     return $this->query($query, $model);
                     // Re-run the query
                 }
             }
             throw new DatabaseLayer\TableDoesntExistException($e->getCode() . ": " . $e->getMessage());
         default:
             // Write exception to log.
             if (DatabaseLayer::getInstance()->getLogger()) {
                 DatabaseLayer::getInstance()->getLogger()->addError("Active Record Exception in " . $model . "\n\n" . $e->getCode() . ": " . $e->getMessage() . "\n\nrunning:\n\n{$query}");
             }
             throw new DatabaseLayer\Exception($e->getCode() . ": " . $e->getMessage() . ".\n\n" . $query);
     }
 }
開發者ID:Thruio,項目名稱:ActiveRecord,代碼行數:27,代碼來源:Base.php

示例2: __construct

 /**
  * Constructor.
  *
  * @param \PDOException $exception The PDO exception to wrap.
  */
 public function __construct(\PDOException $exception)
 {
     parent::__construct($exception->getMessage(), 0, $exception->getPrevious());
     $this->code = $exception->getCode();
     $this->errorInfo = $exception->errorInfo;
     $this->errorCode = isset($exception->errorInfo[1]) ? $exception->errorInfo[1] : $exception->getCode();
     $this->sqlState = isset($exception->errorInfo[0]) ? $exception->errorInfo[0] : $exception->getCode();
 }
開發者ID:Nercury,項目名稱:dbal,代碼行數:13,代碼來源:PDOException.php

示例3: createFromPDOException

 /**
  * @param \PDOException $exception
  * @return MySqlException
  */
 public static function createFromPDOException(\PDOException $exception)
 {
     $message = $exception->getMessage();
     $codePosition = strpos($message, "[{$exception->getCode()}]");
     if ($codePosition !== false) {
         $message = trim(substr($message, $codePosition + strlen("[{$exception->getCode()}]") + 1));
     }
     return new MySqlException($message, $exception->getCode());
 }
開發者ID:oktopost,項目名稱:squid,代碼行數:13,代碼來源:MySqlException.php

示例4: throwExceptionWithInfo

 /**
  * Throw DbException with query info
  *
  * @param string        $sql
  * @param array         $params
  * @param \PDOException $e
  *
  * @throws DbException
  */
 protected function throwExceptionWithInfo($sql, array $params, \PDOException $e)
 {
     $exception = new DbException($e->getMessage(), (int) $e->getCode(), $e);
     $exception->setSql($sql);
     $exception->setParams($params);
     throw $exception;
 }
開發者ID:nafigator,項目名稱:Veles,代碼行數:16,代碼來源:PdoAdapter.php

示例5: __construct

 public function __construct(\PDOException $e, $extraMessage = '')
 {
     // Strip boring unnecessary info from error message
     $strippedMsg = preg_replace('/SQLSTATE\\[[A-Za-z-0-9]+\\]( \\[[A-Za-z-0-9]+\\])?:?\\s?/', '', $e->getMessage());
     // PDOExceptions' getCode() can  return a code with letters, which normal
     // exceptions won't accept. A converted code is better than no code at all though.
     parent::__construct($strippedMsg . $extraMessage, (int) $e->getCode());
 }
開發者ID:starweb,項目名稱:starlit-db,代碼行數:8,代碼來源:DbException.php

示例6: __construct

 /**
  * Create a new query excetion instance.
  *
  * @param  string  $sql
  * @param  array  $bindings
  * @param  \PDOException $previous
  * @return void
  */
 public function __construct($sql, array $bindings, $previous)
 {
     $this->sql = $sql;
     $this->bindings = $bindings;
     $this->previous = $previous;
     $this->code = $previous->getCode();
     $this->errorInfo = $previous->errorInfo;
     $this->message = $this->formatMessage($sql, $bindings, $previous);
 }
開發者ID:spikomino,項目名稱:site,代碼行數:17,代碼來源:QueryException.php

示例7: throwException

 /**
  * @param PDOException $exception
  */
 public function throwException(PDOException $exception)
 {
     if ($this->debug) {
         echo '<pre>';
         print_r(array($exception->getMessage(), $exception->getCode()));
         echo '</pre>';
         die;
     }
 }
開發者ID:AdrianTrainorPHP,項目名稱:FormHandler,代碼行數:12,代碼來源:CustomPDO.php

示例8: testConstruct

 /**
  * @covers       Veles\DataBase\Exceptions\DbException::__construct
  *
  * @param string        $message
  * @param string        $ansi_code
  * @param int           $code
  * @param \PDOException $exception
  *
  * @dataProvider constructProvider
  */
 public function testConstruct($message, $ansi_code, $code, $exception)
 {
     $obj = new DbException($exception->getMessage(), (int) $exception->getCode(), $exception);
     $result = $obj->getMessage();
     $msg = 'Wrong DbException::__construct() behavior!';
     $this->assertSame($message, $result, $msg);
     $result = $obj->getAnsiCode();
     $msg = 'Wrong DbException::__construct() behavior!';
     $this->assertSame($ansi_code, $result, $msg);
     $result = $obj->getCode();
     $msg = 'Wrong DbException::__construct() behavior!';
     $this->assertSame($code, $result, $msg);
 }
開發者ID:nafigator,項目名稱:Veles-unit-tests,代碼行數:23,代碼來源:DbExceptionTest.php

示例9: raw_query

 /**
  * Run RAW Query
  *
  * @param string $sql
  *
  * @return Zend_Db_Statement_Interface
  * @throws PDOException
  */
 public function raw_query($sql)
 {
     try {
         return $this->query($sql);
     } catch (Zend_Db_Statement_Exception $e) {
         // Convert to PDOException to maintain backwards compatibility with usage of MySQL adapter
         $e = $e->getPrevious();
         if (!$e instanceof PDOException) {
             $e = new PDOException($e->getMessage(), $e->getCode());
         }
         throw $e;
     }
 }
開發者ID:dburlage-pantek,項目名稱:Aoe_DbRetry,代碼行數:21,代碼來源:Adapter.php

示例10: __construct

 /**
  * Constructor.
  *
  * @param \PDOException $e
  */
 public function __construct(\PDOException $e)
 {
     if (strstr($e->getMessage(), 'SQLSTATE[')) {
         preg_match('/SQLSTATE\\[(\\w+)\\] \\[(\\w+)\\] (.*)/', $e->getMessage(), $matches);
         if (count($matches)) {
             $this->code = $matches[1] == 'HT000' ? $matches[2] : $matches[1];
             $this->message = $matches[3];
         } else {
             $this->code = $e->getCode();
             $this->message = $e->getMessage();
         }
     }
 }
開發者ID:borobudur-php,項目名稱:borobudur-cqrs,代碼行數:18,代碼來源:PdoException.php

示例11: handlePDOException

 public function handlePDOException(PDOException $e)
 {
     trigger_error('PHP PDO Error in ' . $e->getFile() . ' @' . strval($e->getLine()) . ' [' . strval($e->getCode()) . '] :: ' . $e->getMessage(), E_USER_WARNING);
     foreach ($e->getTrace() as $a => $b) {
         foreach ($b as $c => $d) {
             if ($c == 'args') {
                 foreach ($d as $e => $f) {
                     trigger_error('PHP PDO Error trace: ' . strval($a) . '# args: ' . $e . ': ' . $f . '', E_USER_WARNING);
                 }
             } else {
                 trigger_error('PHP PDO Error trace: ' . strval($a) . '# ' . $c . ': ' . $d . '', E_USER_WARNING);
             }
         }
     }
 }
開發者ID:nexces,項目名稱:transys,代碼行數:15,代碼來源:db.php

示例12: __construct

 /**
  * Constructor
  *
  * @param \PDOException $e      PDO exception
  * @param string        $query  SQL query OPTIONAL
  * @param array         $params SQL query parameters OPTIONAL
  *
  * @return void
  */
 public function __construct(\PDOException $e, $query = null, array $params = array())
 {
     $code = $e->getCode();
     $message = $e->getMessage();
     // Remove user credentials
     if (strstr($message, 'SQLSTATE[') && preg_match('/SQLSTATE\\[(\\w+)\\] \\[(\\w+)\\] (.*)/', $message, $matches)) {
         $code = 'HT000' == $matches[1] ? $matches[2] : $matches[1];
         $message = $matches[3];
     }
     // Add additional information
     if ($query) {
         $message .= PHP_EOL . 'SQL query: ' . $query;
     }
     if ($params) {
         $message .= PHP_EOL . 'SQL query parameters: ' . var_export($params, true);
     }
     $this->code = intval($code);
     $this->message = $message;
 }
開發者ID:kingsj,項目名稱:core,代碼行數:28,代碼來源:PDOException.php

示例13: generateError

 /**
  * Writes a ditailed error message to the log file, if specified.
  * 
  * @param  \PDOException $e
  * @param  string        $strMessage
  * @param  string        $strSql
  * @return void
  */
 private function generateError(\PDOException $e, $strMessage, $strSql = '')
 {
     $strError = PHP_EOL . "\t-- " . $strMessage . PHP_EOL . "\t-- PDOException code: " . $e->getCode() . PHP_EOL . "\t-- File: " . $e->getFile() . PHP_EOL . "\t-- Line: " . $e->getLine() . PHP_EOL . "\t-- Message: " . $e->getMessage() . (empty($strSql) ? '' : PHP_EOL . "\t-- SQL: " . $strSql . PHP_EOL) . PHP_EOL . "\t-------------------------------------------------------" . PHP_EOL . PHP_EOL;
     $this->log($strError, true);
     if (!empty($this->strWriteErrorLogTo)) {
         if (is_resource($this->resourceErrorLog)) {
             fwrite($this->resourceErrorLog, $strError);
         } else {
             $this->resourceErrorLog = fopen($this->strWriteErrorLogTo, 'a');
             if (is_resource($this->resourceErrorLog)) {
                 fwrite($this->resourceErrorLog, $strError);
             }
         }
     }
     unset($strError);
 }
開發者ID:kairuku,項目名稱:FromMySqlToPostgreSql,代碼行數:24,代碼來源:FromMySqlToPostgreSql.php

示例14: convertPostgresException

 /**
  * @link http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html
  */
 protected function convertPostgresException(\PDOException $e, \Exception $root)
 {
     $state = (string) isset($e->errorInfo[0]) ? $e->errorInfo[0] : $e->getCode();
     switch ($state) {
         case '0A000':
             if (strpos($e->getMessage(), 'truncate') !== false) {
                 return new ForeignKeyConstraintViolationException($root->getMessage(), 0, $root);
             }
             break;
         case '23503':
             return new ForeignKeyConstraintViolationException($root->getMessage(), 0, $root);
         case '23505':
             return new UniqueConstraintViolationException($root->getMessage(), 0, $root);
     }
     return new DatabaseException($root->getMessage(), 0, $root);
 }
開發者ID:koolkode,項目名稱:database,代碼行數:19,代碼來源:ExceptionConverterTrait.php

示例15: db_error

 /**
  * 拋出錯誤信息
  *
  * @param PDOException $e
  */
 private function db_error(PDOException $e)
 {
     echo '出錯了!!!<br />';
     echo '錯誤文件:', $e->getFile(), '<br />';
     echo '錯誤行號:', $e->getLine(), '<br />';
     echo '錯誤編碼:', $e->getCode(), '<br />';
     echo '錯誤詳情:', $e->getMessage(), '<br />';
     exit('END...');
 }
開發者ID:0x584A,項目名稱:PHP_Simple_MVC,代碼行數:14,代碼來源:DBPDO.class.php


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