I have a question about a connection to a second host if the first fail down or connection limit reached.
My Host is OVH in France on a shared host (I can't modify apache/php/sql config
) and the MAX USER_CONNECTIONS (sql)
is 30.
I wanted to switch Host is the first one reach the limit and refuse connection.
Can I use ?:
$dbhost = 'localhost';
$dbname = 'dbname';
$dbuser = 'dbuser';
$dbpswd = 'dbpass';
try{
$db = new PDO('mysql:host='.$dbhost.';dbname='.$dbname,$dbuser,$dbpswd,array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}catch(PDOexception $e){
$dbhost2 = 'secondhost';
$dbname2 = 'dbname';
$dbuser2 = 'dbuser';
$dbpswd2 = 'dbpass';
try{
$db = new PDO('mysql:host='.$dbhost2.';dbname='.$dbname2,$dbuser2,$dbpswd2,array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}catch(PDOexception $e){
die("DB Error please contact the web admin.");
}
}
Or if you have a better option..
NB: I do not have much experience in programming, I do not use OOP yet.