How to update remote databse from local databse using PHP ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rthcupid
    New Member
    • Sep 2008
    • 4

    How to update remote databse from local databse using PHP ?

    Hi all

    I need help to update a remote mysql database from a local mysql database using php run in remote site.

    Use of application
    1. The local database and the reomote database are same structure
    2. Some part of updation are done localy and then manully export the the local file and import in remote site . I need help to change this operation by running a scipt in remote server and auomatically update the remote databse from the local databse

    If any one know the idea how to do it . please help me ..

    Thank you all
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    I suggest first writing a test script that connects to both databases and reads from both databases.
    That way any permissions problems can be ironed out.

    Once there is an open connection between both databases in the same script, data can be processed and transferred via arrays.

    Another way around is ftp and mysqldump.
    Update the db locally and run mysqldump.
    FTP the dump file to the remote site.
    Run mysqldump on remote.
    You would need DROP TABLE IF EXISTS in the dump queries so in effect the remote db gets trashed and rebuilt.

    Just a footnote, PHP FTP functions are easy to use but mysqldump is difficult.
    Last edited by code green; Jul 16 '10, 08:12 AM. Reason: Footnote

    Comment

    • rthcupid
      New Member
      • Sep 2008
      • 4

      #3
      Originally posted by code green
      I suggest first writing a test script that connects to both databases and reads from both databases.
      That way any permissions problems can be ironed out.

      Once there is an open connection between both databases in the same script, data can be processed and transferred via arrays.

      Another way around is ftp and mysqldump.
      Update the db locally and run mysqldump.
      FTP the dump file to the remote site.
      Run mysqldump on remote.
      You would need DROP TABLE IF EXISTS in the dump queries so in effect the remote db gets trashed and rebuilt.

      Just a footnote, PHP FTP functions are easy to use but mysqldump is difficult.
      Hi first I could thank for your comments .

      I used the mysql dump . Exactly what I need is a way to acces local database file to the reomote page.

      I have an ftp acces and database access in remote machine . I need to update some of the tables auomaticaly (Daily by setting a clock or by clicking a button).

      Can you show some code snippet for doing that ?

      I dont know how to access the local database in my client machine to the remote site

      Lot of Thanks

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        dont know how to access the local database in my client machine to the remote site
        It is not HOW but CAN that is tricky with a remote site.
        Connecting to a remote database is similar to connecting to a local database
        Code:
        mysql_connect('url','username', 'password');
        URL - This is the address to the database server such as
        'mysite.com/phpMyAdmin/'
        But the ip address is more reliable than the domain name
        Then
        Code:
        mysql_select_db('database_name')
        Can you show some code snippet for doing that ?
        Use mysql_query() to run a query. It is the query itself which is the more difficult/important

        Comment

        • rthcupid
          New Member
          • Sep 2008
          • 4

          #5
          Hi
          I used the following function in my local system


          Code:
          function connectdb()
          {
          $con = mysql_connect('http://<MY IP ADDRESS>/phpmyadmin/', 'dbuser', 'dbpass');
          if (!$con)
            {
            die('Could not connect: ' . mysql_error());
            }
          
          mysql_select_db("mydbname", $con);
          }
          connectdb();

          but i get the following error

          Code:
          Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'IPADDRESS' (4) in '<PATH>' on line 2
          I cannot connect to the database because: Can't connect to MySQL server on 'IPADDRESS' (4)
          what can I do ? please help me.


          Thank you

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            Remove the 'http://' bit.
            Have you got the address correct?
            Is the database in phpmyadmin?
            Try with the IP addres and not the domain name

            Comment

            • Kong Chun Ho
              New Member
              • Jul 2010
              • 34

              #7
              also, the port!

              Comment

              • rthcupid
                New Member
                • Sep 2008
                • 4

                #8
                Hi
                Thanks a lot to touch with me.

                I did not get the connection from local machine with the specified IP address. It had done with as usual procedure. Dump my local database and the import in the Remote server . I m trying to find some way to do this.

                Thanks . thanks a lot

                Comment

                • code green
                  Recognized Expert Top Contributor
                  • Mar 2007
                  • 1726

                  #9
                  Dump my local database and the import in the Remote server
                  FTP. PHP FTP functions work fine

                  Comment

                  Working...