Documentation

getConnection

\Bitrix\Main\DB\Connection public static
\Bitrix\Main\Application::getConnection(
 string $name = ""
);

Static method returns connection with the specified database name. When parameter name is empty, default connection is returned.

Parameters

ParameterDescriptionVersion
$nameConnection name. When empty, uses default connection.

Examples

How to get connection with the database from the application class

$connection = Application::getConnection();
use Bitrix\Main\Application;
use Bitrix\Main\Diag\Debug;

$record = Application::getConnection()
->query("select 1+1;")
->fetch();
Debug::writeToFile($record); 

Get name of connected database:

\Bitrix\Main\Application::getConnection()->getDatabase()


User Comments

User comments are not part of official documentation. Use information provided by other users in the comments at your own risk.

The User Comments section is not to be used as a feature discussion board. Only registered users can post comments. Your comment will be visible once it has been approved by the moderator.
© «Bitrix Inc.», 2001-2021, «Bitrix Inc.», 2021