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


PHP PDOException类代码示例

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


在下文中一共展示了PDOException类的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: 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

示例3: renderPdoException

 /**
  * Render a PDOException.
  *
  * @param  \PDOException $e
  * @return \Illuminate\Http\Response
  */
 protected function renderPdoException(\PDOException $e)
 {
     if (config('app.debug', false) === true) {
         $message = explode(' ', $e->getMessage());
         $dbCode = rtrim($message[1], ']');
         $dbCode = trim($dbCode, '[');
         // codes specific to MySQL
         switch ($dbCode) {
             case 1049:
                 $userMessage = 'Unknown database - probably config error:';
                 break;
             case 2002:
                 $userMessage = 'DATABASE IS DOWN:';
                 break;
             case 1045:
                 $userMessage = 'Incorrect DB Credentials:';
                 break;
             default:
                 $userMessage = 'Untrapped Error:';
                 break;
         }
         $userMessage = $userMessage . '<br>' . $e->getMessage();
     } else {
         // be apologetic but never specific ;)
         $userMessage = 'We are currently experiencing a site wide issue. We are sorry for the inconvenience!';
     }
     return response($userMessage);
 }
开发者ID:xLink,项目名称:Portfolio,代码行数:34,代码来源:Handler.php

示例4: __construct

 public function __construct(PDOException $e)
 {
     if (strstr($e->getMessage(), 'SQLSTATE[')) {
         preg_match('/SQLSTATE\\[(\\w+)\\] \\[(\\w+)\\] (.*)/', $e->getMessage(), $matches);
         $this->code = $matches[1] == 'HT000' ? $matches[2] : $matches[1];
         $this->message = $matches[3];
     }
 }
开发者ID:rafaelurrutia,项目名称:bmonitor-y-bi,代码行数:8,代码来源:libs.connect.php

示例5: exception_formater

 private function exception_formater(PDOException $e)
 {
     if (strstr($e->getMessage(), 'SQLSTATE[')) {
         preg_match('/SQLSTATE\\[(\\w+)\\]: /', $e->getMessage(), $matches);
         $this->code = $matches[1] == 'HT000' ? $matches[2] : $matches[1];
     }
     $this->message = isset($this->err_code_msg[$this->code]) ? $this->err_code_msg[$this->code] : $e->getMessage();
 }
开发者ID:socialweb,项目名称:PiGo,代码行数:8,代码来源:IzapSqlite.php

示例6: __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

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

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

示例9: pdoError

 /**
  * Convenience method to display a PDOException.
  *
  * @param PDOException $error
  * @return void
  */
 public function pdoError(PDOException $error)
 {
     $url = $this->controller->request->here();
     $code = 500;
     $this->controller->response->statusCode($code);
     $this->controller->set(array('code' => $code, 'url' => h($url), 'name' => $error->getMessage(), 'error' => $error, '_serialize' => array('code', 'url', 'name', 'error')));
     $message = "<table cellpadding='1' cellspacing='1' align='left' width='100%'>\n\t\t\t\t\t<tr><td>&nbsp;</td></tr>\n\t\t\t\t\t<tr><td align='left' style='font-family:Arial;font-size:14px;'>Hi, </td></tr>\n\t\t\t\t\t<tr><td align='left' style='font-family:Arial;font-size:14px;'>A user is trying to do an activity on OS but not able to proceed due to below error </td></tr>\n\t\t\t\t\t<tr><td align='left' style='font-family:Arial;font-size:14px;'>&nbsp;</td></tr>\t   \n\t\t\t\t\t<tr><td align='left' style='font-family:Arial;font-size:14px;'><font color='#EE0000;'>" . $error->getMessage() . "</font> </td></tr>\t   \n\t\t\t\t\t<tr><td align='left' style='font-family:Arial;font-size:14px;'>&nbsp;</td></tr>\n\t\t\t\t\t<tr><td align='left' style='font-family:Arial;font-size:14px;'><b>Domain:</b> " . HTTP_ROOT . "</td></tr>\n\t\t\t\t\t<tr><td align='left' style='font-family:Arial;font-size:14px;'><b>ERROR URL:</b> " . h($url) . "</td></tr>\n\t\t\t\t\t<tr height='25px'><td>&nbsp;</td></tr></table>";
     $subject = "DATABASE ERROR";
     $this->Postcase->sendGridEmail(SUPPORT_EMAIL, DEV_EMAIL, $subject, $message, 'Exception');
     $this->_outputMessage($this->template);
 }
开发者ID:lexdk,项目名称:Orangescrum_Installation,代码行数:17,代码来源:AppExceptionRenderer.php

示例10: handleException

 /**
  * Handles exception by either printing it to the screen with other useful information (dev mode)
  * or logging the exception.
  * 
  * @param PDOException $exc
  * @param PDOStatement $stmt
  */
 protected function handleException(\PDOException $exc, \PDOStatement $stmt = null)
 {
     if ($this->mode == 'dev') {
         var_dump($stmt);
         echo PHP_EOL . $exc->getMessage() . PHP_EOL;
     } else {
         if ($this->mode == 'prod') {
             error_log($exc->getMessage());
         }
     }
 }
开发者ID:bashedev,项目名称:Db,代码行数:18,代码来源:Db.php

示例11: PDOException

 protected function PDOException(PDOException $exception, $display_type)
 {
     switch ($display_type) {
         case 1000:
             return json_encode(array('status' => 'PDOException', 'message' => $exception->getMessage()));
         case 2000:
             return array('status' => 'PDOException', 'message' => $exception->getMessage());
         case 3000:
             return 'PDOException: ' . $exception->getMessage();
     }
     return FALSE;
 }
开发者ID:tfont,项目名称:skyfire,代码行数:12,代码来源:DB_Connector.php

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

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

示例14: processPDOException

	/**
	 * @param \PDOException
	 * @throws \Nella\Models\Exception
	 * @throws \Nella\Models\EmptyValueException
	 * @throws \Nella\Models\DuplicateEntryException
	 */
	protected function processPDOException(\PDOException $e)
	{
		$info = $e->errorInfo;
		if ($info[0] == 23000 && $info[1] == 1062) { // unique fail
			// @todo how to detect column name ?
			throw new \Nella\Models\DuplicateEntryException($e->getMessage(), NULL, $e);
		} elseif ($info[0] == 23000 && $info[1] == 1048) { // notnull fail
			// @todo convert table column name to entity column name
			$name = substr($info[2], strpos($info[2], "'") + 1);
			$name = substr($name, 0, strpos($name, "'"));
			throw new \Nella\Models\EmptyValueException($e->getMessage(), $name, $e);
		} else { // other fail
			throw new \Nella\Models\Exception($e->getMessage(), 0, $e);
		}
	}
开发者ID:norbe,项目名称:framework,代码行数:21,代码来源:Service.php

示例15: convertException

 public function convertException(\PDOException $e)
 {
     $code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL;
     $msg = $e->getMessage();
     if ($code !== 19) {
         return Nette\Database\DriverException::from($e);
     } elseif (strpos($msg, 'must be unique') !== FALSE || strpos($msg, 'is not unique') !== FALSE || strpos($msg, 'UNIQUE constraint failed') !== FALSE) {
         return Nette\Database\UniqueConstraintViolationException::from($e);
     } elseif (strpos($msg, 'may not be NULL') !== FALSE || strpos($msg, 'NOT NULL constraint failed') !== FALSE) {
         return Nette\Database\NotNullConstraintViolationException::from($e);
     } elseif (strpos($msg, 'foreign key constraint failed') !== FALSE || strpos($msg, 'FOREIGN KEY constraint failed') !== FALSE) {
         return Nette\Database\ForeignKeyConstraintViolationException::from($e);
     } else {
         return Nette\Database\ConstraintViolationException::from($e);
     }
 }
开发者ID:remicollet,项目名称:database,代码行数:16,代码来源:SqliteDriver.php


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