Answer the question
In order to leave comments, you need to log in
Bitrix is it possible to use the Bitrix API for the second connection to the database?
There is a second connection to the database specified in settings.php
I call the connection
$connection = Bitrix\Main\Application::getConnection('testdb');
$sqlHelper = $connection->getSqlHelper();
Answer the question
In order to leave comments, you need to log in
Yes, you can. Absolutely nothing gets in the way.
$obElements = CIBlockElement::GetList(
// ...
);
while ($element = $obElements->Fetch()) {
// code here
}
Is it possible to execute CIBlockElement::GetList to a third-party database and how to do it?
const CONN_DEFAULT = '';
private static $poolDB = [];
final public static function changeGlobalDB(string $name = '')
{
global $DB;
if (empty(self::$poolDB)) {
self::$poolDB[self::CONN_DEFAULT] = $DB;
}
if (!isset(self::$poolDB[$name])) {
$conn = Application::getConnection($name)->getConfiguration();
self::$poolDB[$name] = new \CDatabase();
self::$poolDB[$name]->Connect($conn['host'], $conn['database'], $conn['login'], $conn['password'], $name);
}
return $DB = self::$poolDB[$name];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question