• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/db/mysqlidbconnection.php
  • Класс: BitrixMainDBMysqliDbConnection
  • Вызов: MysqliDbConnection::connectInternal
protected function connectInternal()
{
	if ($this->isConnected)
		return;

	$dbHost = $this->dbHost;
	$dbPort = 0;
	if (($pos = strpos($dbHost, ":")) !== false)
	{
		$dbPort = intval(substr($dbHost, $pos + 1));
		$dbHost = substr($dbHost, 0, $pos);
	}
	if (($this->dbOptions & self::PERSISTENT) != 0)
		$dbHost = "p:".$dbHost;

	/** @var $connection mysqli */
	$connection = mysqli_init();
	if (!$connection)
		throw new ConnectionException('Mysql init failed');

	if (!empty($this->dbInitCommand))
	{
		if (!$connection->options(MYSQLI_INIT_COMMAND, $this->dbInitCommand))
			throw new ConnectionException('Setting mysql init command failed');
	}

	if ($dbPort > 0)
		$r = $connection->real_connect($dbHost, $this->dbLogin, $this->dbPassword, $this->dbName, $dbPort);
	else
		$r = $connection->real_connect($dbHost, $this->dbLogin, $this->dbPassword, $this->dbName);

	if (!$r)
		throw new ConnectionException(
			'Mysql connect error',
			sprintf('(%s) %s', $connection->connect_errno, $connection->connect_error)
		);

	$this->resource = $connection;
	$this->isConnected = true;

	// nosql memcached driver
	if (isset($this->configuration['memcache']))
	{
		$memcached = BitrixMainApplication::getInstance()->getDbConnectionPool()->getConnection($this->configuration['memcache']);
		mysqlnd_memcache_set($this->resource, $memcached->getResource());
	}


	//global $DB, $USER, $APPLICATION;
	if ($fn = BitrixMainLoader::getPersonal("php_interface/after_connect_d7.php"))
		include($fn);
}