473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Build a table copied from different database in PHP

290 100+
Hello
I am wanting to copy all data from one table to another.

I am using PHP and MySQL

I have done this with tables that in the the same database,
but is it possible to do this with tables that are run by different
virtual servers ?

So I want to quickly build a new table on QR-KUPONS from MOBI6

This is my "usual" backup script.


Expand|Select|Wrap|Line Numbers
  1. $sql = "DROP TABLE IF EXISTS `pages_backup`";
  2. $result = mysql_query($sql)
  3.     or die("could not DROP pages_backup.". mysql_error());  
  4.  
  5. echo "DROPPED pages_backup Table <br>";
  6.  
  7. $sql = "CREATE TABLE `pages_backup` LIKE `pages`";
  8. $result = mysql_query($sql)    or write_error("Could not CREATE TABLE pages_backup.".mysql_error()."\r\n");
  9.  
  10. $sql = "INSERT INTO `pages_backup` SELECT * FROM `pages`";
  11. $result = mysql_query($sql)    or write_error("Could not INSERT INTO  pages_backup.".mysql_error()."\r\n");
  12.  
  13. echo "COMPLETED BACK UP OF PAGES<br>";  
When I have wanted to access a different server in the past I
have logged on as that user on the database ... like this.

Expand|Select|Wrap|Line Numbers
  1. // CHANGE SERVER TO: MOBI6
  2.  
  3. $host = "localhost";
  4. $user = "mobi677d"; 
  5. $password = "xxx password xxx"; 
  6. $database = "mobi677d"; 
  7. $connection = mysql_connect($host,$user,$password) or die ("Couldn't connect to server.");
  8. $db = mysql_select_db($database, $connection) or die ("Couldn't select database.");    
  9.  
  10. do my stuff, then back again.
  11.  
  12. // CHANGE BACK TO SERVER : QR-KUPONS
  13. $host = "localhost";
  14. $user = "kup823"; 
  15. $password ="xxx password xxx"; 
  16. $database = "kup823"; 
  17. $connection = mysql_connect($host,$user,$password) or die ("Couldn't connect to server.");
  18. $db = mysql_select_db($database, $connection) or die ("Couldn't select database.");
I am not sure how I would combine these two so I can quickly build a new
table on QR-KUPONS from MOBI6

I should say, that the databases are on the same physical server and use the same MySQL
database.

Any thoughts ?
Thanks.
Sep 4 '14 #1
0 1087

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: nfr | last post by:
Default build directories seem to be somewhat different between C# and Visual Basic.NET. Both have "Debug" and "Release" directories under "obj". However, Visual Studio.NET defaults to a single...
0
by: MLH | last post by:
I used the following SQL to create a new table in a database on a remote MySQL server by copying one already there. I know the table exists SOMEWHERE in cyberspace. I can read its data, write to...
1
by: Pat | last post by:
i've one dev and one prod, one of the table in dev database having 70 millions records and need to export to one of the table in prod database. both machine got 2 nic, one 10/100 mbps and the other...
3
by: Jason | last post by:
In enterprise manager I am copying a table from one database to another. I am using the dts wizard to import the data. After I successfully import the data, I open both tables to compare the...
1
by: yateen joshi | last post by:
Hi , I am developing a script that will delete old data from various tables in a database periodically. The script deletes data from all the tables, one by one, in single go. I have two options...
2
by: Agnes | last post by:
I can export the data to an excel(quit slow , for 5k records, It need 20mins) Now, my problem is how can I join another table from another database ? "select I.invno,I.company,C.telno,C.faxno from...
1
by: Peschello | last post by:
I am attempting to copy table data from our live production database to our development database. To do this, I need to specify the name of the database in addition to the table name. I'm running...
6
by: Ted | last post by:
I am construvcting a number of databases, some of which contain sensitive data and most of which do not. I am attempting to handle the security issues involved in protecting sensitive data in part...
4
by: kcopson | last post by:
I need a routine to add a new field to an existing table in a database that is in another town. Situation: I maintain a database with 10 copies in different offices. Everytime we want to make a...
1
by: okonita | last post by:
Hi all, I have a need to copy data from one database/schema to a different database schema. Yes, I can use export/import but that is not "elegant". Yes, I can try a redirected Restore from Backup...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.