It’s unlikely that the database server on your shared hosting site is set to support database replication.
that colud be true, i don’t know that.
ok, then if i use the main database (shared hosting) but the database (vps) is only a backup (1 week age maybe)? it’s posible do what i explain? change to the database (vps) if database (sahred hosting) is down?
what you want to do probably is not possible through shared hosting. If your site can’t be down, you should look into high-availability hosting. It’s not cheap. Or you can look for a more reliable host.
really? i can’t connect me to a external database? i need try a little. but… if this is possible, wordpress can do that?
Yes, you can do that, but dynamically switching won’t work if your shared host is down.
You may have half a chance of dynamically switching to an alternate DB if your primary one is down. It depends if the failure occurs upon reconnecting or initial connect. If reconnecting, like Steve says — it won’t work.
If the initial connection fails, you can create a custom DB error handling file called db-error.php that is placed in /wp-content/. Relevant Code.
Complete speculation now. A solution appears plausible, but I couldn’t say it would actually work. This error handler could instantiate another wpdb class object, connecting to the alternate DB. You eventually would then assign that object to the global $wpdb variable. I don’t know if you can do so within the error handler, the swap may need to be deferred until the original object instantiation is complete. The error handler would need to return true to avoid killing the thread, which could cause the object to be unstable since there is no valid connection. Thus I’m not sure this would even work, but it might be worth a try.
@sterndata: no, no, my shard hosting only have down the data base mysql, not the apache.
@bcworkz: i will try. thank you