SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2002
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Copy mySQL table from one server to another?

    Hi all,

    I need to copy a specific mysql table from one server to another using php. I have looked into the var_export function, but have no idea where to start, other than being able to connect to their server via php's ftp function.

    Does anyone know of a function that can use a php ftp connection to copy a table from one database to another one on a different server?

    Thanks in advance,
    David

  2. #2
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    You could export the table using phpMyAdmin and then import it on the new server.

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2002
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This will be a reoccurring setup, I am hoping to write my own code that will automate the process, so I don't have use a third party like phpMyAdmin manually.

    I already have an ftp connection created with the other server, I just need to copy the table from here to there.

  4. #4
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    FTP won't do it unless you have access to the entire filesystem. In that case can copy the mysql/data/tablename directory between servers. The best way would be to use a web service.

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2002
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't there a way for php on my server to "backup" a table, and then have the php on the other server "import" the backup file (the backup file could be retrieved by php's ftp function).

  6. #6
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Yeah, using phpMyAdmin

    Seriously, the best bet would be to create a PHP file like this
    PHP Code:
    <?php
    /* mysql connection here */
    $sql "select *
            from tablename" 
    ;
    $rs mysql_query($sql);

    while ( 
    $row mysql_fetch_array($rs) ) {
        
    $rowset[] = $row;
    }
    $output serialize($rowset);

    die( 
    $output );
    ?>
    and then setup another PHP file on the receiving server to open the URL of the above file, unserialize() the output and load it into the table on that server. Much easier than FTP.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •