• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/db/pgsqlconnection.php
  • Класс: BitrixMainDBPgsqlConnection
  • Вызов: PgsqlConnection::connectInternal
protected function connectInternal()
{
	if ($this->isConnected)
	{
		return;
	}

	$host = $this->host;
	$port = 0;
	if (($pos = strpos($host, ":")) !== false)
	{
		$port = intval(substr($host, $pos + 1));
		$host = substr($host, 0, $pos);
	}

	$connectionString = " host='" . addslashes($host) . "'";
	if ($port > 0)
	{
		$connectionString .= " port='" . addslashes($port) . "'";
	}
	$connectionString .= " dbname='" . addslashes($this->database) . "'";
	$connectionString .= " user='" . addslashes($this->login) . "'";
	$connectionString .= " password='" . addslashes($this->password) . "'";

	if (isset($this->configuration['charset']))
	{
		$connectionString .= " options='--client_encoding=" . $this->configuration['charset'] . "'";
	}

	set_error_handler([$this, 'connectionErrorHandler']);
	if ($this->options & self::PERSISTENT)
	{
		$connection = @pg_pconnect($connectionString);
	}
	else
	{
		$connection = @pg_connect($connectionString);
	}
	restore_error_handler();

	if (!$connection)
	{
		throw new ConnectionException(
			'Pgsql connect error ['.$this->host.']',
			error_get_last()['message']
		);
	}

	$this->resource = $connection;
	$this->isConnected = true;

	$this->afterConnected();
}