function db_connect_plus(){ // returns a link identifier on success, or false on error
$primary = "localhost"; // Primary MySQL host info
$primary_uid = "primary_mysql_username";
$primary_pwd = "primary_mysql_password";
$secondary = "backup.mysql.servername"; // Secondary MySQL host info
$secondary_uid = "secondary_mysql_username";
$secondary_pwd = "secondary_mysql_password";
$timeout = 15; // timeout in seconds
error_reporting(0); // Turn off error reporting in case one is down.
if ($fp = fsockopen($primary, 3306, &$errno, &$errstr, $timeout)) {
fclose($fp);
return $clm = mysql_pconnect($primary, $primary_uid, $primary_pwd);
}
if ($fp = fsockopen($secondary, 3306, &$errno, &$errstr, $timeout)) {
fclose($fp);
return $clm = mysql_pconnect($secondary, $secondary_uid, $secondary_pwd);
}
return 0;
}
$current_db = db_connect_plus(); // Get connection
/*
* If the mysql host is localhost, set the primary server's db name
* Otherwise, set the db name for the secondary server
*/
if (strchr(mysql_get_host_info(), "localhost")) {
$database_name = "primary_db_name";
} else {
$database_name = "secondary_db_name";
}
Added On: 2004-02-03
508 | XHTML 1.0 | CSS 2.0 | PHP 5.2.11 | MySQL 5.0.89 | RSS 2.0 | Print
Copyright © 2010 Chris Martin