public function connect() { if ($this->_connection) { return; } if (static::$_set_names === NULL) { // Determine if we can use mysql_set_charset(), which is only // available on PHP 5.2.3+ when compiled against MySQL 5.0+ static::$_set_names = !function_exists('mysql_set_charset'); } // Extract the connection parameters, adding required variabels extract($this->_config['connection'] + array('database' => '', 'hostname' => '', 'username' => '', 'password' => '', 'persistent' => FALSE)); // Prevent this information from showing up in traces unset($this->_config['connection']['username'], $this->_config['connection']['password']); try { if ($persistent) { // Create a persistent connection $this->_connection = mysql_pconnect($hostname, $username, $password); } else { // Create a connection and force it to be a new link $this->_connection = mysql_connect($hostname, $username, $password, TRUE); } } catch (ErrorException $e) { // No connection exists $this->_connection = NULL; throw new \Database_Exception(mysql_error(), mysql_errno()); } // \xFF is a better delimiter, but the PHP driver uses underscore $this->_connection_id = sha1($hostname . '_' . $username . '_' . $password); $this->_select_db($database); if (!empty($this->_config['charset'])) { // Set the character set $this->set_charset($this->_config['charset']); } }
public function connect() { if ($this->_connection) { return; } if (static::$_set_names === null) { // Determine if we can use mysqli_set_charset(), which is only // available on PHP 5.2.3+ when compiled against MySQL 5.0+ static::$_set_names = !function_exists('mysqli_set_charset'); } // Extract the connection parameters, adding required variables extract($this->_config['connection'] + array('database' => '', 'hostname' => '', 'port' => '', 'socket' => '', 'username' => '', 'password' => '', 'persistent' => false, 'compress' => true)); // Prevent this information from showing up in traces unset($this->_config['connection']['username'], $this->_config['connection']['password']); try { if ($socket != '') { $port = null; } elseif ($port != '') { $socket = null; } else { $socket = null; $port = null; } if ($persistent) { // Create a persistent connection if ($compress) { $mysqli = mysqli_init(); $mysqli->real_connect('p:' . $hostname, $username, $password, $database, $port, $socket, MYSQLI_CLIENT_COMPRESS); $this->_connection = $mysqli; } else { $this->_connection = new \MySQLi('p:' . $hostname, $username, $password, $database, $port, $socket); } } else { // Create a connection and force it to be a new link if ($compress) { $mysqli = mysqli_init(); $mysqli->real_connect($hostname, $username, $password, $database, $port, $socket, MYSQLI_CLIENT_COMPRESS); $this->_connection = $mysqli; } else { $this->_connection = new \MySQLi($hostname, $username, $password, $database, $port, $socket); } } if ($this->_connection->error) { // Unable to connect, select database, etc throw new \Database_Exception($this->_connection->error, $this->_connection->errno); } } catch (\ErrorException $e) { // No connection exists $this->_connection = null; throw new \Database_Exception('No MySQLi Connection<br>\\n' . $e->getMessage() . "<br>\n" . "hostname:" . $hostname . "<br>\n" . "username:"******"<br>\n" . "password:"******"<br>\n" . "database:" . $database . "<br>\n" . "port:" . $port . "<br>\n", 0); throw new \Database_Exception('No MySQLi Connection', 0); } // \xFF is a better delimiter, but the PHP driver uses underscore $this->_connection_id = sha1($hostname . '_' . $username . '_' . $password); if (!empty($this->_config['charset'])) { // Set the character set $this->set_charset($this->_config['charset']); } static::$_current_databases[$this->_connection_id] = $database; }
public function connect() { if ($this->_connection) { return; } if (static::$_set_names === null) { // Determine if we can use mysql_set_charset(), which is only // available on PHP 5.2.3+ when compiled against MySQL 5.0+ static::$_set_names = !function_exists('mysql_set_charset'); } // Extract the connection parameters, adding required variabels extract($this->_config['connection'] + array('database' => '', 'hostname' => '', 'port' => '', 'socket' => '', 'username' => '', 'password' => '', 'persistent' => false, 'compress' => true)); // Prevent this information from showing up in traces unset($this->_config['connection']['username'], $this->_config['connection']['password']); try { // Build right first argument for mysql_connect() if ($socket != '') { $hostname = $hostname . ':' . $socket; } elseif ($port != '') { $hostname = $hostname . ':' . $port; } if ($persistent) { // Create a persistent connection if ($compress) { $this->_connection = mysql_pconnect($hostname, $username, $password, MYSQL_CLIENT_COMPRESS); } else { $this->_connection = mysql_pconnect($hostname, $username, $password); } } else { // Create a connection and force it to be a new link if ($compress) { $this->_connection = mysql_connect($hostname, $username, $password, true, MYSQL_CLIENT_COMPRESS); } else { $this->_connection = mysql_connect($hostname, $username, $password, true); } } } catch (\ErrorException $e) { // No connection exists $this->_connection = null; throw new \Database_Exception(mysql_error(), mysql_errno()); } // \xFF is a better delimiter, but the PHP driver uses underscore $this->_connection_id = sha1($hostname . '_' . $username . '_' . $password); $this->_select_db($database); if (!empty($this->_config['charset'])) { // Set the character set $this->set_charset($this->_config['charset']); } }
public function connect() { if ($this->_connection) { return; } if (static::$_set_names === NULL) { // Determine if we can use mysqli_set_charset(), which is only // available on PHP 5.2.3+ when compiled against MySQL 5.0+ static::$_set_names = !function_exists('mysqli_set_charset'); } // Extract the connection parameters, adding required variables extract($this->_config['connection'] + array('database' => '', 'hostname' => '', 'port' => '', 'username' => '', 'password' => '', 'persistent' => FALSE)); // If a port is set in config append it to hostname !empty($port) and $hostname = "{$hostname}:{$port}"; // Prevent this information from showing up in traces unset($this->_config['connection']['username'], $this->_config['connection']['password']); try { if ($persistent) { // Create a persistent connection $this->_connection = new \mysqli('p:' . $hostname, $username, $password, $database); } else { // Create a connection and force it to be a new link $this->_connection = new \mysqli($hostname, $username, $password, $database); } if ($this->_connection->error) { // Unable to connect, select database, etc throw new \Database_Exception($this->_connection->error, $this->_connection->errno); } } catch (ErrorException $e) { // No connection exists $this->_connection = NULL; throw new \Database_Exception('No MySQLi Connection', 0); } // \xFF is a better delimiter, but the PHP driver uses underscore $this->_connection_id = sha1($hostname . '_' . $username . '_' . $password); if (!empty($this->_config['charset'])) { // Set the character set $this->set_charset($this->_config['charset']); } static::$_current_databases[$this->_connection_id] = $database; }