Are you first creating a new database first with mysql_create_db() before trying to run your schema? What error message do you get? The code you've posted is only creating a table.
Also, rather than opening and reading in an external file or doing all those $sql .= lines, you might have an easier time using heredoc syntax, which would let you do something like
$sql = <<<SQL
CREATE TABLE IP_Dept (
IP_Addr int(10) unsigned NOT NULL default
DeptID int(10) unsigned NOT NULL default
...etc
SQL;
$result = mysql_query($sql,$linkI);
(hopefully $linkI is your mysql connection) This way you don't have to bother with all that quoting.
-bill
Daevid Vincent wrote:
I need to use PHP to duplicate the schema of a mysql database. This
seems like it should be a simple task -- taking a 'template' db and
cloning it with a new name.
I've tried things like:
$filename = "myDB.sql";
$fd = fopen ($filename, "r");
$sql = fread ($fd, filesize ($filename));
fclose ($fd);
And
$lines = file($filename);
foreach ($lines as $line_num => $line) { $sql .= $line;
}
And
$sql .= "CREATE TABLE IP_Dept (";
$sql .= " IP_Addr int(10) unsigned NOT NULL default
'0',";
$sql .= " DeptID int(10) unsigned NOT NULL default
'0'";
$sql .= ");";
$sql .= "CREATE TABLE ResolveTable (";
$sql .= " IP_Addr int(10) unsigned NOT NULL default
'0',";
$sql .= " Name char(255) NOT NULL default '',";
$sql .= " Custom char(1) default NULL,";
$sql .= " Global char(1) default 'Y',";
$sql .= " OSVersion char(255) default NULL,";
$sql .= " RowID int(10) unsigned NOT NULL
auto_increment,";
$sql .= " Display enum('Yes','No') NOT NULL default
'Yes',";
$sql .= " PRIMARY KEY (RowID)";
$sql .= ");";
echo "<PRE>".$sql."</PRE><P>";
$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 <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
--------------------------------------------------------------------- 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 <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php