Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test for MySQL server and try another if not found

Status
Not open for further replies.

makaveliuk

Programmer
Dec 1, 2003
46
GB
Is there a way to have a PHP script try to connect to a server and try another server if a connection cannot be established?

I have tried the following:

$link = @mysql_connect(server, username, password);
if( !$link ) {
$link = @mysql_connect(backupserver, username, password);
if( !$link ) {
header("Location: ./error.html");
}
}

But that fails every time if the first server is unavailable even though the 'backupserver' is available.

Any ideas where I'm going wrong? Is there a way to test for a connection without actually connecting maybe?
 
I mean it directs to error.html every time (As in the second failure) but if I remove the first one it works so there connection is definately available on the backup server.
 
Under the assumption that you have posted pseudocode (you don't have $'s in front of your variable names), I can't duplicate your error.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Those variables are declared using:

define(server, "192.000.000.000"); //Not the correct IP obviously

So they don't need $'s, I can't see any reason why shouldn't work either but for some reason it doesn't, it's weird.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top