public function initialize()
{
/* If an established connection is available, then there's
* no need to connect and select the database.
*
* Depending on the database driver, conn_id can be either
* boolean TRUE, a resource or an object.
*/
if ($this->conn_id) {
return TRUE;
}
// ----------------------------------------------------------------
// Connect to the database and set the connection ID
$this->conn_id = $this->db_connect($this->pconnect);
// No connection resource? Check if there is a failover else throw an error
if (!$this->conn_id) {
// Check if there is a failover set
if (!empty($this->failover) && is_array($this->failover)) {
// Go over all the failovers
foreach ($this->failover as $failover) {
// Replace the current settings with those of the failover
foreach ($failover as $key => $val) {
$this->{$key} = $val;
}
// Try to connect
$this->conn_id = $this->db_connect($this->pconnect);
// If a connection is made break the foreach loop
if ($this->conn_id) {
break;
}
}
}
// We still don't have a connection?
if (!$this->conn_id) {
// log_message('error', 'Unable to connect to the database');
if ($this->db_debug) {
$this->display_error('db_unable_to_connect');
}
return FALSE;
}
}
// Now we set the character set and that's all
return $this->db_set_charset($this->char_set);
}