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 anyone finds any error and want to adjust. Please do it.
Some error appears in the
$con2
?– rray
You can also set up a replication between banks. So you work with only one bank and the changes will be reflected to the other automatically.
– Franchesco
@Rray doesn’t seem any mistake
– Amanda Lima
@Earendul in this case, this is not feasible.
– Amanda Lima