MySQL copy table to remote database with PHP
Posted: Mon Apr 16, 2007 5:59 am
Hi everyone
I have a pretty specific question here relating to the ability to copy databases and tables between servers.
We have an intranet MySQL server but one of the database tables needs to also live on our ISPs MySQL.
At the moment I export our intranet version of the table with phpMyAdmin, then import the SQL file into the remote phpMyAdmin.
I was wondering if there's a way to do this automatically with PHP?
For example there's the Copy database to option in phpMyAdmin and I had a bit of a dig around the source files to see how it was achieved but couldn't get anything.
Is there a MySQL function to let me do this in one hit?
Or would I be best off doing it manually with this process...
1) Loop through the records in the local copy, building a MySQL statement as I go
2) Truncate the remote table
3) Run the MySQL statement which INSERTS all the records
We're talking 50-100 records here so the above would work ok.
I was wondering if anyone knew of a better way to do this?
Thanks
Ben
I have a pretty specific question here relating to the ability to copy databases and tables between servers.
We have an intranet MySQL server but one of the database tables needs to also live on our ISPs MySQL.
At the moment I export our intranet version of the table with phpMyAdmin, then import the SQL file into the remote phpMyAdmin.
I was wondering if there's a way to do this automatically with PHP?
For example there's the Copy database to option in phpMyAdmin and I had a bit of a dig around the source files to see how it was achieved but couldn't get anything.
Is there a MySQL function to let me do this in one hit?
Or would I be best off doing it manually with this process...
1) Loop through the records in the local copy, building a MySQL statement as I go
2) Truncate the remote table
3) Run the MySQL statement which INSERTS all the records
We're talking 50-100 records here so the above would work ok.
I was wondering if anyone knew of a better way to do this?
Thanks
Ben