[eluser]Eric Brown[/eluser]
I'm trying to implement failover logic into my code. I'd like to get some opinions on how to best do this. Essentially all of my writes should go to "DB01" but if the connection is unavailable because the server crashed or it's under high load or there is a routing issue, I'd like the app to fail over to DB02. Here's what I have. Thanks for your comments and suggestions
Code:
//Load DB01 Master
$this->db = $this->load->database('db01',TRUE);
if($this->db->conn_id!=""){
// verify DB01 master connected
$this->db_connected == TRUE;
}
else{
// if not connected, fail over to second master
// Load DB02 Master
$this->db = $this->load->database('db02',TRUE);
if($this->db->conn_id!=""){
$this->db_connected == TRUE;
}
else{
// if not connected, no database connection available
$this->db_connected == FALSE;
}
}