protected function connectInternal() { if ($this->isConnected) { return; } $dbHost = $this->dbHost; $dbPort = 0; if (($pos = strpos($dbHost, ":")) !== false) { $dbPort = intval(substr($dbHost, $pos + 1)); $dbHost = substr($dbHost, 0, $pos); } if (($this->dbOptions & self::PERSISTENT) != 0) { $dbHost = "p:" . $dbHost; } /** @var $connection \mysqli */ $connection = \mysqli_init(); if (!$connection) { throw new ConnectionException('Mysql init failed'); } if (!empty($this->dbInitCommand)) { if (!$connection->options(MYSQLI_INIT_COMMAND, $this->dbInitCommand)) { throw new ConnectionException('Setting mysql init command failed'); } } if ($dbPort > 0) { $r = $connection->real_connect($dbHost, $this->dbLogin, $this->dbPassword, $this->dbName, $dbPort); } else { $r = $connection->real_connect($dbHost, $this->dbLogin, $this->dbPassword, $this->dbName); } if (!$r) { throw new ConnectionException('Mysql connect error', sprintf('(%s) %s', $connection->connect_errno, $connection->connect_error)); } $this->resource = $connection; $this->isConnected = true; // nosql memcached driver if (isset($this->configuration['memcache'])) { $memcached = \Freetrix\Main\Application::getInstance()->getConnectionPool()->getConnection($this->configuration['memcache']); mysqlnd_memcache_set($this->resource, $memcached->getResource()); } //global $DB, $USER, $APPLICATION; if ($fn = \Freetrix\Main\Loader::getPersonal("php_interface/after_connect_d7.php")) { include $fn; } }
/** * Establishes a connection to the database. * Includes php_interface/after_connect_d7.php on success. * Throws exception on failure. * * @return void * @throws \Bitrix\Main\DB\ConnectionException */ 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); } if (($this->options & self::PERSISTENT) != 0) { $host = "p:" . $host; } /** @var $connection \mysqli */ $connection = \mysqli_init(); if (!$connection) { throw new ConnectionException('Mysql init failed'); } if (!empty($this->initCommand)) { if (!$connection->options(MYSQLI_INIT_COMMAND, $this->initCommand)) { throw new ConnectionException('Setting mysql init command failed'); } } if ($port > 0) { $r = $connection->real_connect($host, $this->login, $this->password, $this->database, $port); } else { $r = $connection->real_connect($host, $this->login, $this->password, $this->database); } if (!$r) { throw new ConnectionException('Mysql connect error [' . $this->host . ']', sprintf('(%s) %s', $connection->connect_errno, $connection->connect_error)); } $this->resource = $connection; $this->isConnected = true; // nosql memcached driver if (isset($this->configuration['memcache'])) { $memcached = \Bitrix\Main\Application::getInstance()->getConnectionPool()->getConnection($this->configuration['memcache']); mysqlnd_memcache_set($this->resource, $memcached->getResource()); } $this->afterConnected(); }