You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
<?php
|
|
/**
|
|
* Класс базы данных.
|
|
* Возвращает идентификатор соединения
|
|
*
|
|
* @copyright
|
|
* @link
|
|
* @package Majestic
|
|
* @subpackage DB
|
|
* @since
|
|
* @version SVN: $Id$
|
|
* @filesource $URL$
|
|
*/
|
|
class DBConnector
|
|
{
|
|
static private $handlers = array();
|
|
static public $queries = array();
|
|
|
|
/**
|
|
* Получение соединения.
|
|
* Если соединение с такими параметрами уже есть - новое не создается.
|
|
*
|
|
* @param array $db_settings - массив настроек
|
|
* @return resource - идентификатор соединения
|
|
*/
|
|
static function getConnect($db_settings)
|
|
{
|
|
$handler_name = self::getConnectionName($db_settings);
|
|
|
|
if (isset(self::$handlers[$handler_name])) {
|
|
return self::$handlers[$handler_name];
|
|
}
|
|
|
|
if (!$handler = mysqli_connect($db_settings['host'], $db_settings['user'], $db_settings['password'], $db_settings['database'])) {
|
|
throw new MJException('Can\'t connect to DB '.mysqli_connect_error(), 2);
|
|
}
|
|
|
|
mysqli_query($handler, "SET NAMES 'utf8'"); //cheat!!!
|
|
return self::$handlers[$handler_name] = $handler;
|
|
}
|
|
|
|
static function getConnectionName($db_settings)
|
|
{
|
|
return $db_settings['host'].'-'.$db_settings['database'];
|
|
}
|
|
}
|
|
?>
|