I'm trying to write a DB connection failover script in PHP for a web form that uses a MS SQL DB. The Db is replicated to another server for disaster recovery purposes. I would like to have my script to try to connect to the primary SQL server and if fails, roll to the backup DB. I've done this in ASP but having problems writing this in PHP.
if($connect2 = @mssql_connect("nbrchwse01", "user", "password")){
$connect = mssql_connect("nbrchwse01", "user", "password");
}else{
$connect = mssql_connect("rchapcfb", "user", "password");
}
I've also tried:
if(!($connect2 = @mssql_connect("nbrchwse01", "user", "password"))){
$connect = mssql_connect("rchapcfb", "user", "password");
}
The part that's confusing me is that it's not consistant. Sometimes it will work and sometimes it will hang for a long time and sometimes i'll get a 'page cannot be displayed' error.
Running on Apache2
PHP 4.4.0-dev
Win2K server