summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
Diffstat (limited to 'system/database')
-rw-r--r--system/database/DB_driver.php37
1 files changed, 32 insertions, 5 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index cc40ba48a..c2d57a833 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -126,16 +126,43 @@ class CI_DB_driver {
// Connect to the database and set the connection ID
$this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
- // No connection resource? Throw an error
+ // No connection resource? Check if there is a failover else throw an error
if ( ! $this->conn_id)
{
- log_message('error', 'Unable to connect to the database');
+ // 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;
+ }
- if ($this->db_debug)
+ // Try to connect
+ $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_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)
{
- $this->display_error('db_unable_to_connect');
+ log_message('error', 'Unable to connect to the database');
+
+ if ($this->db_debug)
+ {
+ $this->display_error('db_unable_to_connect');
+ }
+ return FALSE;
}
- return FALSE;
}
// ----------------------------------------------------------------