/** * Database object constructor * * @param array List of options used to configure the connection * @since 1.5 * @see JDatabase */ function __construct($options) { $host = array_key_exists('host', $options) ? $options['host'] : 'localhost'; $user = array_key_exists('user', $options) ? $options['user'] : ''; $password = array_key_exists('password', $options) ? $options['password'] : ''; $database = array_key_exists('database', $options) ? $options['database'] : ''; $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : 'jos_'; $select = array_key_exists('select', $options) ? $options['select'] : true; // Perform a number of fatality checks, then return gracefully if (!function_exists('mysql_connect')) { $this->_errorNum = 1; $this->_errorMsg = JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQL'); return; } // Connect to the server if (!($this->_connection = @mysql_connect($host, $user, $password, true))) { $this->_errorNum = 2; $this->_errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL'); return; } // Finalize initialisation parent::__construct($options); // Set sql_mode to non_strict mode mysql_query("SET @@SESSION.sql_mode = '';", $this->_connection); // select the database if ($select) { $this->select($database); } }
/** * Database object constructor * * @param array List of options used to configure the connection * @since 1.5 * @see JDatabase */ function __construct($options) { $host = array_key_exists('host', $options) ? $options['host'] : 'localhost'; $user = array_key_exists('user', $options) ? $options['user'] : ''; $password = array_key_exists('password', $options) ? $options['password'] : ''; $database = array_key_exists('database', $options) ? $options['database'] : ''; $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : 'jos_'; $select = array_key_exists('select', $options) ? $options['select'] : true; // Perform a number of fatality checks, then return gracefully if (!function_exists('mysql_connect')) { $this->_errorNum = 1; $this->_errorMsg = 'The MySQL adapter "mysql" is not available.'; return; } // Connect to the server if (!($this->_connection = @mysql_connect($host, $user, $password, true))) { $this->_errorNum = 2; $this->_errorMsg = 'Could not connect to MySQL'; return; } // Finalize initialisation parent::__construct($options); // select the database if ($select) { $this->select($database); } }
/** * This special constructor reuses the existing resource from the existing db connecton * * @param unknown_type $options */ function __construct($options) { $db =& JFactory::getDBO(); $select = array_key_exists('select', $options) ? $options['select'] : true; $database = array_key_exists('database', $options) ? $options['database'] : ''; // perform a number of fatality checks, then return gracefully if (!function_exists('mysql_connect')) { $this->_errorNum = 1; $this->_errorMsg = 'The MySQL adapter "mysql" is not available.'; return; } // connect to the server $this->_resource =& $db->_resource; // finalize initialization JDatabase::__construct($options); // select the database if ($select) { $this->select($database); } }
/** * Constructor. * * @param array $options List of options used to configure the connection * * @return void * * @since 11.1 */ protected function __construct($options) { // Get some basic values from the options. $options['host'] = isset($options['host']) ? $options['host'] : 'localhost'; $options['user'] = isset($options['user']) ? $options['user'] : '******'; $options['password'] = isset($options['password']) ? $options['password'] : ''; $options['database'] = isset($options['database']) ? $options['database'] : ''; $options['select'] = isset($options['select']) ? (bool) $options['select'] : true; // Make sure the MySQL extension for PHP is installed and enabled. if (!function_exists('mysql_connect')) { // Legacy error handling switch based on the JError::$legacy switch. // @deprecated 11.3 if (JError::$legacy) { $this->errorNum = 1; $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQL'); return; } else { throw new DatabaseException(JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQL')); } } // Attempt to connect to the server. if (!($this->connection = @mysql_connect($options['host'], $options['user'], $options['password'], true))) { // Legacy error handling switch based on the JError::$legacy switch. // @deprecated 11.3 if (JError::$legacy) { $this->errorNum = 2; $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL'); return; } else { throw new DatabaseException(JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL')); } } // Finalize initialisation parent::__construct($options); // Set sql_mode to non_strict mode mysql_query("SET @@SESSION.sql_mode = '';", $this->connection); // If auto-select is enabled select the given database. if ($options['select'] && !empty($options['database'])) { $this->select($options['database']); } }
/** * This special constructor reuses the existing resource from the existing db connecton * * @param unknown_type $options */ function __construct($options) { $db = JFactory::getDBO(); // support for recovery of existing connections (Martin N. Brampton) if (isset($this->_options)) { $this->_options = $options; } $select = array_key_exists('select', $options) ? $options['select'] : true; $database = array_key_exists('database', $options) ? $options['database'] : ''; // perform a number of fatality checks, then return gracefully if (!function_exists('mysqli_connect')) { $this->_errorNum = 1; $this->_errorMsg = 'The MySQL adapter "mysqli" is not available.'; return; } // connect to the server $this->_resource = $db->_resource; // finalize initialization JDatabase::__construct($options); // select the database if ($select) { $this->select($database); } }
/** * Constructor. * * @param array $options List of options used to configure the connection * * @return void * * @since 11.1 */ protected function __construct($options) { // Get some basic values from the options. $options['host'] = isset($options['host']) ? $options['host'] : 'localhost'; $options['user'] = isset($options['user']) ? $options['user'] : '******'; $options['password'] = isset($options['password']) ? $options['password'] : ''; $options['database'] = isset($options['database']) ? $options['database'] : ''; $options['select'] = isset($options['select']) ? (bool) $options['select'] : true; $options['port'] = null; $options['socket'] = null; /* * Unlike mysql_connect(), mysqli_connect() takes the port and socket as separate arguments. Therefore, we * have to extract them from the host string. */ $tmp = substr(strstr($options['host'], ':'), 1); if (!empty($tmp)) { // Get the port number or socket name if (is_numeric($tmp)) { $options['port'] = $tmp; } else { $options['socket'] = $tmp; } // Extract the host name only $options['host'] = substr($options['host'], 0, strlen($options['host']) - (strlen($tmp) + 1)); // This will take care of the following notation: ":3306" if ($options['host'] == '') { $options['host'] = 'localhost'; } } // Make sure the MySQLi extension for PHP is installed and enabled. if (!function_exists('mysqli_connect')) { // Legacy error handling switch based on the JError::$legacy switch. // @deprecated 12.1 if (JError::$legacy) { $this->errorNum = 1; $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQLI'); return; } else { throw new JDatabaseException(JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQLI')); } } // Attempt to connect to the server. if (!($this->connection = @mysqli_connect($options['host'], $options['user'], $options['password'], null, $options['port'], $options['socket']))) { // Legacy error handling switch based on the JError::$legacy switch. // @deprecated 12.1 if (JError::$legacy) { $this->errorNum = 2; $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL'); return; } else { throw new JDatabaseException(JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL')); } } // Finalize initialisation parent::__construct($options); // Set sql_mode to non_strict mode mysqli_query($this->connection, "SET @@SESSION.sql_mode = '';"); // If auto-select is enabled select the given database. if ($options['select'] && !empty($options['database'])) { $this->select($options['database']); } }
/** * Constructor. * * @param array $options List of options used to configure the connection * * @since 11.1 */ protected function __construct($options) { // Get some basic values from the options. $options['host'] = isset($options['host']) ? $options['host'] : 'localhost'; $options['user'] = isset($options['user']) ? $options['user'] : ''; $options['password'] = isset($options['password']) ? $options['password'] : ''; $options['database'] = isset($options['database']) ? $options['database'] : ''; $options['select'] = isset($options['select']) ? (bool) $options['select'] : true; // Build the connection configuration array. $config = array('Database' => $options['database'], 'uid' => $options['user'], 'pwd' => $options['password'], 'CharacterSet' => 'UTF-8', 'ReturnDatesAsStrings' => true); // Make sure the SQLSRV extension for PHP is installed and enabled. if (!function_exists('sqlsrv_connect')) { // Legacy error handling switch based on the JError::$legacy switch. // @deprecated 12.1 if (JError::$legacy) { $this->errorNum = 1; $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_ADAPTER_SQLSRV'); return; } else { throw new JDatabaseException(JText::_('JLIB_DATABASE_ERROR_ADAPTER_SQLSRV')); } } // Attempt to connect to the server. if (!($this->connection = @sqlsrv_connect($options['host'], $config))) { // Legacy error handling switch based on the JError::$legacy switch. // @deprecated 12.1 if (JError::$legacy) { $this->errorNum = 2; $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_SQLSRV'); return; } else { throw new JDatabaseException(JText::_('JLIB_DATABASE_ERROR_CONNECT_SQLSRV')); } } // Make sure that DB warnings are not returned as errors. sqlsrv_configure('WarningsReturnAsErrors', 0); // Finalize initialisation parent::__construct($options); // If auto-select is enabled select the given database. if ($options['select'] && !empty($options['database'])) { $this->select($options['database']); } }
/** * Database object constructor * * @param array List of options used to configure the connection * @since 1.5 * @see JDatabase */ function __construct($options) { $host = array_key_exists('host', $options) ? $options['host'] : 'localhost'; $user = array_key_exists('user', $options) ? $options['user'] : ''; $password = array_key_exists('password', $options) ? $options['password'] : ''; $database = array_key_exists('database', $options) ? $options['database'] : ''; $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : 'jos_'; $select = array_key_exists('select', $options) ? $options['select'] : true; // Unlike mysql_connect(), mysqli_connect() takes the port and socket // as separate arguments. Therefore, we have to extract them from the // host string. $port = NULL; $socket = NULL; $targetSlot = substr(strstr($host, ":"), 1); if (!empty($targetSlot)) { // Get the port number or socket name if (is_numeric($targetSlot)) { $port = $targetSlot; } else { $socket = $targetSlot; } // Extract the host name only $host = substr($host, 0, strlen($host) - (strlen($targetSlot) + 1)); // This will take care of the following notation: ":3306" if ($host == '') { $host = 'localhost'; } } // perform a number of fatality checks, then return gracefully if (!function_exists('mysqli_connect')) { $this->_errorNum = 1; $this->_errorMsg = JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQLI'); return; } // connect to the server if (!($this->_connection = @mysqli_connect($host, $user, $password, NULL, $port, $socket))) { $this->_errorNum = 2; $this->_errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL'); return; } // finalize initialization parent::__construct($options); // Set sqli_mode to non_strict mode mysqli_query($this->_connection, "SET @@SESSION.sql_mode = '';"); // select the database if ($select) { $this->select($database); } }
function __construct($host = 'localhost', $user, $pass, $db = '', $table_prefix = '', $offline = true) { parent::__construct('mysql', $host, $user, $pass, $db, $table_prefix); }
/** * Constructor. * * @param array $options Array of database options with keys: host, user, password, database, select. * * @since 11.1 */ protected function __construct($options) { // Get some basic values from the options. $options['host'] = isset($options['host']) ? $options['host'] : 'localhost'; $options['user'] = isset($options['user']) ? $options['user'] : '******'; $options['password'] = isset($options['password']) ? $options['password'] : ''; $options['database'] = isset($options['database']) ? $options['database'] : ''; $options['select'] = isset($options['select']) ? (bool) $options['select'] : true; // Make sure the PDO MySQL extension for PHP is installed and enabled. if (!class_exists('PDO')) { // Legacy error handling switch based on the JError::$legacy switch. // @deprecated 12.1 if (JError::$legacy) { $this->errorNum = 1; $this->errorMsg = 'The PDO adapter "pdo" is not available.'; return; } else { throw new JDatabaseException('The PDO adapter "pdo" is not available.'); } } // Add extra configuration options as necessary $extras = array(); if (isset($options['ssl_ca']) && $options['ssl_ca'] && $options['host'] != 'localhost') { $extras[PDO::MYSQL_ATTR_SSL_CA] = $options['ssl_ca']; } // Attempt to connect to the server. if (!($this->connection = new PDO("mysql:host={$options['host']}", $options['user'], $options['password'], $extras))) { // Legacy error handling switch based on the JError::$legacy switch. // @deprecated 12.1 if (JError::$legacy) { $this->errorNum = 2; $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL'); return; } else { throw new JDatabaseException(JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL')); } } $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Finalize initialisation parent::__construct($options); // Set sql_mode to non_strict mode // mysql_query("SET @@SESSION.sql_mode = '';", $this->connection); // If auto-select is enabled select the given database. if ($options['select'] && !empty($options['database'])) { $this->select($options['database']); } }
/** * Database object constructor * * @access public * @param array List of options used to configure the connection * @since 1.5 * @see JDatabase */ function __construct($options) { $host = array_key_exists('host', $options) ? $options['host'] : 'localhost'; $user = array_key_exists('user', $options) ? $options['user'] : ''; $password = array_key_exists('password', $options) ? $options['password'] : ''; $database = array_key_exists('database', $options) ? $options['database'] : ''; $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : 'jos_'; $select = array_key_exists('select', $options) ? $options['select'] : true; // Unlike mysql_connect(), mysqli_connect() takes the port and socket // as separate arguments. Therefore, we have to extract them from the // host string. $port = NULL; $socket = NULL; $targetSlot = substr(strstr($host, ":"), 1); if (!empty($targetSlot)) { // Get the port number or socket name if (is_numeric($targetSlot)) { $port = $targetSlot; } else { $socket = $targetSlot; } // Extract the host name only $host = substr($host, 0, strlen($host) - (strlen($targetSlot) + 1)); // This will take care of the following notation: ":3306" if ($host == '') { $host = 'localhost'; } } // perform a number of fatality checks, then return gracefully if (!function_exists('mysqli_connect')) { $this->_errorNum = 1; $this->_errorMsg = 'The MySQL adapter "mysqli" is not available.'; return; } // connect to the server if (!($this->_resource = @mysqli_connect($host, $user, $password, NULL, $port, $socket))) { $this->_errorNum = 2; $this->_errorMsg = 'Could not connect to MySQL'; return; } // finalize initialization parent::__construct($options); // select the database if ($select) { $this->select($database); } }