简体   繁体   中英

Is there a way in PHP to upload database from localhost to cloud? MySQL

Is there a way in PHP to upload database from localhost to cloud with just one click? What I am thinking if it is possible to have a button in my system for localhost (offline system) only. Then the code of it is: if there is a internet connection, the localhost database will update the cloud database. Or anyway for it to do it? TIA.

I'm not expert in that, but I think you can do that. For that you have to first check that you are connected or not by writing php script that checks your connect.

example :

<?php
function is_connected()
{
    $connected = @fsockopen("www.example.com", 80); 
                                        //website, port  (try 80 or 443)
    if ($connected){
        $is_conn = true; //action when connected
        fclose($connected);
    }else{
        $is_conn = false; //action in connection failure
    }
    return $is_conn;

}
?>

And then you can write your update query with remote_db connection details( DB_user_name, db_password, db_name, etc ) if connection = true . And in else part you can update your local_db .

And you can call this function on_click event.

Hope this answer will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM