How to set primary and secondary database on php mysql
In PHP & MYSQL,
How to set primary and secondary database configuration,
How to set Following actions.
- Should update records on both primary and secondary,
- If secondary DB not connected then records should update on secondary, later these missed records should update on primary as well.
- at any time, prim and se开发者_JAVA技巧condary should have same counts.
- how to handles all these thing, problematically or through configuration setting.
- Currently i am working in local individual desktop, not in network share.so hvaing only one phpmyadmin and WAMP,
The php side of things should almost never be responsible for worrying about things like database failover. Generally you want to use some kind of database middleware if you're that concerned. However the easiest answer I can give you for these particular needs is to go with a MySQL master master setup, and randomly connect to one of the two masters from your php code.
I'm not sure. Do you want to use different kinds of databases(mysql, sqlite, oracle, sqlserver ...) or different databases in your mysql (or another) database?
If different mysql databases, than I think you should use different mysql connections.
for example,
<?php
$server = "localhost";
$user = "root";
$password = "admin";
$database1 = "mydb1";
$database1 = "mydb2";
$workWithFirstDatabase = mysql_connect($server, $user, $password);
if (mysql_select_database($database, $workWithFirstDatabase)) {
mysql_query("INSERT INTO TABLE `mytable` VALUES ('1','Hello','First','Database')",
$workWithFirstDatabase);
}
$workWithSecondDatabase = mysql_connect($server, $user, $password);
if (mysql_select_database($database, $workWithSecondDatabase)) {
mysql_query("INSERT INTO TABLE `mytable` VALUES ('1','Hello','Second','Database')",
$workWithSecondDatabase);
}
?>
精彩评论