Saniok, Держи:
Незабудь установить обработчик не пойманных исключений set_exception_handler() иначе будет ошибку выбивать ну или просто die вместо throw поставь в конструкторе
<?php
/**
* Db
* Provides access to the database
* @author Screamer <nwotnbm@gmail.com>
*/
class Db extends mysqli
{
/**
* @var (array)
* Contains all errors which were occured
*/
protected $_debug_messages = array();
/**
* Construct
* Get connection parameters. Connect to mysql server. Setup connection charset
* Description of connection parameters:
* @param (string) $host hostname
* @param (string) $user username
* @param (string) $password password
* @param (string) $db database
* @param (string) $charset charset
* @throws (Exception) Unable to connect to MySQL server
* @return (void)
*/
public function __construct($host = 'localhost', $user = 'root', $password = '', $db = 'localhost', $charset = 'utf8')
{
if (parent::__construct($host, $user, $password, $db) === FALSE) {
throw new Exception('Unable to connect to MySQL server. Check your configuration file.');
}
// Setup charset
$this->query("SET NAMES " . $charset);
}
/**
* Analog of mysql_result()
* @param (mysqli_result) $result result of query
* @return (string)
*/
public function result(mysqli_result $result)
{
$result = $result->fetch_row();
return $result[0];
}
public function query($statement, $type = MYSQLI_USE_RESULT)
{
$result = parent::query($statement, $type);
if (!empty($this->error)) {
$this->_debug_messages[] = 'Error: ' . $this->errno . ' ' . $this->error . '
' . 'Statement: ' . $statement;
}
return $result;
}
public function close()
{
parent::close();
try {
if (!empty($this->_debug_messages)) {
// LOG
throw new Exception('<pre>DB ERROR
' . implode('
--
', $this->_debug_messages) . '</pre>');
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
}