Question: How can I put 2 or more database connection in one PHP file with a case that one or more servers are not connecting to the network?
The Story Line Sorry if this question is already existed, but I already searched it and still I don't quite understand..
so, I'm trying to make a simple distributed database system using MySQL, and I'm not using any complicated stuffs since I'm a complete beginner... I use a standard connection on MySQL (mysql_connect)...in I put it as an included file... because it's a distributed database, in which in one website there'll be more than one connection attemp to make, if one of the connection failed...
like this, I made two conn file..it's just examples though...
<?php
$server="192.168.0.3";
$user="user";
$pass="pass";
$db="db_1";
$conn = mysql_connect($server,$user,$pass);
if(!$conn) die "connection error";
$sel_db = mysql_select_db($db,$conn);
if(!sel_db) die "wrong db";
?>
so I made the second one with db_2 as the database... and I put the on the website using if..
<?php
require_once "conn_1.php";
if (empty($conn)) {
require_once "conn_2.php";
}
?>
and I intentionally close/cut the connection on the first server...so if the first connect attemp failed, it will goes to the second one.. but it ended up showing error "trying to connect to a unexisted host", well I forgot about the detail but something like that...and didn't show anything else..
so I tried to close the second server... I thought the result will be different, it has to be showing a normal result since the first connection didn't fail...but the result is, the website still showed a same warning error..
so I just thought that instead of using those connection files, I have to put an IP tracking code to check the other server is online or not, and then called the connection file...
or is it another way to do it...?
Sorry if you don't understand my question, please tell me if my question is a bit confusing.. and thanks..