It is currently Wed Feb 08, 2012 5:33 pm

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Managing multiple PHP MySQL Connections
PostPosted: Fri Feb 05, 2010 12:25 pm 
Offline

Joined: Fri Feb 05, 2010 11:02 am
Posts: 2
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 06, 2010 11:32 pm 
Offline

Joined: Sun May 02, 2004 11:34 pm
Posts: 6500
Location: toronto, canada
I believe that the CREATE TABLE LIKE only works when the DBs are the on the same server, housed in the same mysql instance.

I would use the SHOW CREATE TABLE tableName syntax to retrieve the create table statement from the DB and run it in the other server[/code]

_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 08, 2010 6:05 pm 
Offline

Joined: Mon Feb 01, 2010 6:56 pm
Posts: 4
Try to use

Code:
show tables


and

Code:
desc <table_name>


queries. Seems it's what you need...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to: