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()


© «Bitrix24», 2001-2024
Up