[thelist] copying a db tables to multiple servers

Jeffrey Barke jeffrey.barke at themechanism.com
Mon Aug 11 05:43:42 CDT 2008

On Aug 11, 2008, at 4:53 AM, Jeremy Weiss wrote:

> I need to pull data from one database and upload it to others.  
> However, I'll need to create the tables before I can insert the data  
> and I'm not sure how to get the information from the primary  
> database needed to create the table on the other servers. I've been  
> playing with "SHOW COLUMNS FROM tablename" but this doesn't appear  
> to be giving me the indexes, collation. So, I guess what I'm asking  
> is, what's the easiest way, in PHP 5, to grab the structure of a  
> table from a database on one server and use it to create the needed  
> table in another database on another server?

Hello, Jeremy,

AFAIK, the SHOW CREATE TABLE SQL statement is the easiest way:

$sql = 'SHOW CREATE TABLE ' . $tblName;
$res = mysql_query($sql);
if ($res) {
	$data = mysql_fetch_row($res);
	echo $data[1];


Jeffrey Barke
Senior developer / information architect
New York

More information about the thelist mailing list