Current location: Hot Scripts Forums » Programming Languages » PHP » Managing multiple PHP MySQL Connections


Managing multiple PHP MySQL Connections

Reply
  #1 (permalink)  
Old 02-05-10, 01:46 AM
PHP_Prema PHP_Prema is offline
New Member
 
Join Date: Feb 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Managing multiple PHP MySQL Connections

I m trying to create a new table on server B as like a table on server A in php script.
The steps I did are,
1. Using mysql_connect() and mysql_select_db() I established connection on Server A & B with 2 different variable sets, say variable $db1 holds the db of Server A and variable $db2 holds the db of Server B.

2. Tables are list from both the DBs

3. Needed to create missing tables on Server B [ie., copy missed tables with rows from server A to Server B]. Here, it is struggling................

How to create or copy a specific table from one server to another server or IP in PHP ???


Here is my code:
<?php
#Staging
$hostname='localhost';
$un= 'admin';
$pwd='******';
$db='instglive';
$link=mysql_connect($hostname, $un, $pwd);
if(!$link)
die('Could not connect: ' . mysql_error());

if(!mysql_select_db($db,$link))
die('Could not link db: ' . mysql_error());


#Live
$hostname1='222.666.73.91';
$un1= 'test';
$pwd1='*******';
$db1='testdb';
$link1=mysql_connect($hostname1, $un1, $pwd1);
if(!$link1)
die('Could not connect: ' . mysql_error());

if(!mysql_select_db($db1,$link1))
die('Could not link db: ' . mysql_error());


$d="CREATE TABLE ".$db1.".".student." LIKE ".$db.".".student";
if(!mysql_query($d)) echo mysql_error();

?>

I need to work out the create table query on instglive db...
Can anybody help??????
Its urgent.

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 02-05-10, 06:31 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Can you use phpMyAdmin?

If it doesn't have to be a PHP script, the easiest and fastest way is to use the commandline.

This will dump the database from one server to another. You have to create the new database and user first.

mysqldump -uuser -p database -hhost | mysql -unewuser -p newdatabase -hnewhost

You can also dump like so:

mysqldump -uuser -p database -hhost > sql.dump

then copy the file to the new server and read it in with

mysql -unewuser -p newdatabase -hnewhost < sql.dump

Check the commandline options.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
IIS MYSQL and PHP nommiiss PHP 6 01-31-06 04:30 PM
WEB HOSTING - $4.99/MONTH For 1GB HD & 25GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 10-06-05 08:22 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
Complex mysql sorting pb (Get cat_list from cids &pcids with 1 query, willing to pay) aqw PHP 1 06-23-05 07:02 PM
help with multiple select used with php and mysql isaacmlee PHP 2 10-15-04 01:34 PM


All times are GMT -5. The time now is 08:10 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.