/** * Метод получения коннекта к БД * * @return ADOConnection */ protected final function getConnection() { if ($this->CONNECTION != null) { return $this->CONNECTION; //--- } if (!$this->isConfigured()) { PsUtil::raise('Cannot get DB connection, {} is not configured.', get_called_class()); } $this->LOGGER->info(); $this->LOGGER->info('? Connection for [{}] is requested', $this->CONNECTION_PARAMS); $URL = $this->CONNECTION_PARAMS->url(); //Посмотрим, есть ли у нас нужный коннект if (array_key_exists($URL, $this->CONNECTIONS)) { $this->LOGGER->info('< Fast returned from cache'); return $this->CONNECTION = $this->CONNECTIONS[$URL]; } //Отлогируем $this->LOGGER->info('+ Establishing connection {}', $this->CONNECTION_PARAMS); //Подключаем adodb PsLibs::inst()->AdoDb(); //Подключаемся $this->CONNECTION = ADONewConnection($URL); if (!is_object($this->CONNECTION)) { PsUtil::raise("Unable to connect to [{}]", $this->CONNECTION_PARAMS); } //Зададим некоторые настройки $this->CONNECTION->debug = ADODB_DEBUG; $this->CONNECTION->SetFetchMode(ADODB_FETCH_ASSOC); $this->CONNECTION->query("SET NAMES 'utf8'"); $this->CONNECTION->query("SET CHARACTER SET 'utf8'"); //Положим соединение в пул if (array_key_exists($URL, $this->CONNECTIONS)) { raise_error('Double trying to register db connection'); } $this->LOGGER->info('< Established connection returned'); return $this->CONNECTIONS[$URL] = $this->CONNECTION; }