<?php
 class DBException extends \Exception { public $errorMsg = null; public $errorNo = null; public $query = null; public $queryParams = null; public function __construct($message, $query=null, $queryParams=null, $code = 0, $previous = null) { global $db; $this->query = $query; $this->queryParams = $queryParams; $errorMsg = ''; if ($db) { $this->errorMsg = $db->ErrorMsg(); $this->errorNo = $db->ErrorNo(); $errorMsg = "{$this->errorMsg} [code:{$this->errorNo}]"; } else { $errorMsg = '[DB OBJECT DESTROYED]'; } $logMessage = ''; if ($this->query) { $logMessage = sprintf("%s, query: %s,\nerror: %s", $message, $this->query, $errorMsg); } else { $logMessage = sprintf("error: %s,\nmessage: %s", $message, $errorMsg); } $logMessage = "[DBException] $logMessage"; \Log::getInstance()->dbError($logMessage, [ 'queryParams' => new \Engine\Logger\Context\Auto($this->queryParams), ], $this->errorNo, $this->errorMsg, $this->query); parent::__construct($message, $code, $previous); } } 