0

I have extended the mysqli database class to make query handling more efficient and it works well so far. However, sometimes my database server will go down and then basically lots of parts break. So I want to adapt my database class to connect to a second failover server, without having to change the rest of my PHP code.

Is it really bad if I do this like this:

protected $fallback = 'mysql_fallback';

    public function __construct($host = "mysql", $user = "xxx", $pass = "xxx", $db = "xxx", $port=null, $socket=null) {         
        @parent::__construct($host, $user, $pass, $db, $port, $socket);
        if ($this->connect_errno) {
            @parent::__construct($this->fallback, $user, $pass, $db, $port, $socket);
        }
    }

In all my scripts I have the following:

$db = new myDbase();`
if (!$db->connect_errno)`{

And I don't really want to change all the scripts where I have this code and just setup master/master replication on mysql and go this way.

Is there another way to setup failover quickly, without adjusting too much code and still have some kind of transparency?

user1914292
  • 1,586
  • 13
  • 38

0 Answers0