From: Daevid Vincent
Date: December 17 2002 10:31am
Subject: RE: How can I duplicate a mysql template database? [hack]
List-Archive: http://lists.mysql.com/mysql/127673
Message-Id: <002001c2a5b7$70ff4150$0201a8c0@telecom>
MIME-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Seems to me there should be a built in SQL command to duplicate a
database. Jeepers. Or to read in a .sql file from PHP and create a
database out of it (which was the original intent).
Anyways, here's a 'hack'. I'd still love to hear anyone else's more
elegant solution.
$V2DB = "V2_SL".$CompanyID;
$result = mysql_create_db($V2DB, $linkI);
if (!$result) $errorstring .= "Error creating ".$V2DB."
database
\n".mysql_errno($linkI).": ".mysql_error($linkI)."
\n";
mysql_select_db ($V2DB, $linkI) or die ("Could not select ".$V2DB."
Database");
/*
//TODO: None of these below here work. Ugh! so frustrating!!
//$filename = "/mypath/todb/V2_DB.sql";
//$fd = fopen ($filename, "r");
//$sql = fread ($fd, filesize ($filename));
//fclose ($fd);
//$lines = file($filename);
//foreach ($lines as $line_num => $line) { $sql .= $line; }
//$sqlTables = explode(";",$sql);
//foreach ($sqlTables as $table)
//{
// echo "
$table
".$sql."
";
> > > $result = mysql_query($sql,$linkI);
> > >
> > > But ALL of them fail! Ugh!!! Can I not stack commands
> like that? Is
> > > there some way to read in a .sql file via PHP? The problem
> > is that my
> > > web pages are on a web server and the db is on a mysql
> > server which are
> > > different machines, so calling a system() or other execute style
> > > function won't work for me.
> > >
> > > I figured, "Ah! Why don't I just make a template db on the
> > server and
> > > issue some SQL command to 'clone' that and rename it".
> > You'd think that
> > > was pretty straight forward, but I can't find any examples
> > or commands
> > > to do this seemingly trivial task. Ideas?
> > >
> > >
> > >
> >
> ---------------------------------------------------------------------
> > > Before posting, please check:
> > > http://www.mysql.com/manual.php (the manual)
> > > http://lists.mysql.com/ (the list archive)
> > >
> > > To request this thread, e-mail
>