- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/db/mysqliconnection.php
- Класс: BitrixMainDBMysqliConnection
- Вызов: MysqliConnection::connectInternal
protected function connectInternal()
{
if ($this->isConnected)
{
return;
}
$host = $this->host;
$port = 0;
if (($pos = strpos($host, ":")) !== false)
{
$port = intval(substr($host, $pos + 1));
$host = substr($host, 0, $pos);
}
if (($this->options & self::PERSISTENT) != 0)
{
$host = "p:".$host;
}
$connection = mysqli_init();
if (!$connection)
{
throw new ConnectionException('Mysql init failed');
}
if (!empty($this->initCommand))
{
if (!$connection->options(MYSQLI_INIT_COMMAND, $this->initCommand))
{
throw new ConnectionException('Setting mysql init command failed');
}
}
if ($port > 0)
{
$success = $connection->real_connect($host, $this->login, $this->password, $this->database, $port);
}
else
{
$success = $connection->real_connect($host, $this->login, $this->password, $this->database);
}
if (!$success)
{
throw new ConnectionException(
'Mysql connect error ['.$this->host.']',
sprintf('(%s) %s', $connection->connect_errno, $connection->connect_error)
);
}
$this->resource = $connection;
$this->isConnected = true;
if (isset($this->configuration['charset']))
{
$connection->set_charset($this->configuration['charset']);
}
// nosql memcached driver
if (isset($this->configuration['memcache']))
{
if (function_exists('mysqlnd_memcache_set'))
{
$memcached = BitrixMainApplication::getInstance()->getConnectionPool()->getConnection($this->configuration['memcache']);
mysqlnd_memcache_set($this->resource, $memcached->getResource());
}
}
$this->afterConnected();
}