• Модуль: scale
  • Путь к файлу: ~/bitrix/modules/scale/lib/helper.php
  • Класс: BitrixScaleHelper
  • Вызов: Helper::modifyDbconn
static function modifyDbconn($DBHost, $DBName, $DBLogin, $DBPassword)
{
	if($DBHost == '')
		throw new BitrixMainArgumentNullException("DBHost");
	if($DBName == '')
		throw new BitrixMainArgumentNullException("DBName");
	if($DBLogin == '')
		throw new BitrixMainArgumentNullException("DBLogin");

	$filename = BitrixMainApplication::getDocumentRoot()."/bitrix/php_interface/dbconn.php";
	$file = new BitrixMainIOFile($filename);

	if(!$file->isExists())
		return false;

	$content = file_get_contents($filename);

	if($content == '')
		return false;

	file_put_contents(BitrixMainApplication::getDocumentRoot()."/bitrix/php_interface/dbconn.php.bak", $content);

	$content = preg_replace('/($DBHosts*=s*("|')+)(.*)(("|')+;)/','${1}'.$DBHost.'${4}',$content);
	$content = preg_replace('/($DBNames*=s*("|')+)(.*)(("|')+;)/','${1}'.$DBName.'${4}',$content);
	$content = preg_replace('/($DBLogins*=s*("|')+)(.*)(("|')+;)/','${1}'.$DBLogin.'${4}',$content);
	$content = preg_replace('/($DBPasswords*=s*("|')+)(.*)(("|')+;)/','${1}'.$DBPassword.'${4}',$content);

	return file_put_contents($filename, $content);
}