- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/database.php
- Класс: CAllDatabase
- Вызов: CAllDatabase::ConnectInternal
protected function ConnectInternal();
public function DoConnect($connectionName = '')
{
if ($this->connection && $this->connection->isConnected())
{
// the connection can reconnect outside
$this->db_Conn = $this->connection->getResource();
return true;
}
$application = MainApplication::getInstance();
$found = false;
// try to get a connection by its name
$connection = $application->getConnection($connectionName ?: (string)$this->connectionName);
if ($connection instanceof MainDBConnection)
{
// empty connection data, using the default connection
if ((string)$this->DBHost === '')
{
$found = true;
$this->DBHost = $connection->getHost();
$this->DBName = $connection->getDatabase();
$this->DBLogin = $connection->getLogin();
$this->DBPassword = $connection->getPassword();
}
// or specific connection data
if (!$found)
{
$found = (
$this->DBHost == $connection->getHost()
&& $this->DBName == $connection->getDatabase()
&& $this->DBLogin == $connection->getLogin()
);
}
}
// connection not found, adding the new connection to the pool
if (!$found)
{
if ((string)$connectionName === '')
{
$connectionName = "{$this->DBHost}.{$this->DBName}.{$this->DBLogin}";
}
$parameters = [
'host' => $this->DBHost,
'database' => $this->DBName,
'login' => $this->DBLogin,
'password' => $this->DBPassword,
];
$connection = $application->getConnectionPool()->cloneConnection(
ConnectionPool::DEFAULT_CONNECTION_NAME,
$connectionName,
$parameters
);
if ($this->bNodeConnection && ($connection instanceof MainDBConnection))
{
$connection->setNodeId($this->node_id);
}
$found = true;
}
if ($found)
{
// real connection establishes here
$this->db_Conn = $connection->getResource();
$this->connection = $connection;
$this->sqlTracker = null;
$this->cntQuery = 0;
$this->timeQuery = 0;
$this->arQueryDebug = [];
return true;
}
return false;
}