class databaseConfig{
var $default = array(
'host' => '127.0.0.1',
'login' => 'root',
'password' => '',
'database' => 'local',
);
var $server = array(
'host' => '192.168.100.101',
'login' => 'root',
'password' => '',
'database' => 'server',
);
}
class SimpleMySqlConnect{
private $config = array();
private $connections = array();
function __construct(){
if(class_exists("databaseConfig")){
$this->config = new databaseConfig();
}
$connections = get_object_vars($_this->config);
foreach($connections as $name => $config){
$this->connections[$name] = new mysqli($config['host'], $config['login'], $config['password'], $config['database']);
}
}
function getConnection($name){
if(in_array($name, $this->connections)){
return $this->connections[$name];
}
}
function getConnections(){
return $this->connections;
}
}
...
$query = "INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)";
$simpleMySql = new SimpleMySqlConnect();
$connections = $simpleMySql->getConnections();
foreach ($connections as $name => $mySqlClass){
$stmt = $mySqlClass->prepare($query);
$stmt->bind_param("sss", $val1, $val2, $val3);
$val1 = 'Stuttgart';
$val2 = 'DEU';
$val3 = 'Baden-Wuerttemberg';
$stmt->execute();
}
...
Reference
PHP
Obs
I could not test, I do not have Mysql on this computer, if someone finds some error and wants to adjust. Please do it.