I don't know how you would do it from a file off the top of my head, so 
let's invent it, in pseudocode, anyway. The important thing to remember is 
that all of the commands to create or alter tables / databases are SQL 
queries. So the mysql_query() function is used to do most of the work.

We have the database
We have a connection to it
We have the proper user/password for creation rights.
We have a file with the necessary SQL to create a tablle : CREATE TABLE 
..... etc., with no trailing semi-colon.

pseudo code ..
Open the file & get the file handle
Read it all as one chunk, assigning it to a variable, say $sql. If the SQL 
is broken into lines the file will have to be  read and concatenated to the 
Use the variable in a  mysql_query, testing for success.
Issue a mysql_list_tables to see that you have the new tables, if that's 
successful a list_fields for the new table.

Refinements . things to check ...

1. Maybe check for the existence of the table and drop it before you create 
it. That can be done as a mysql_query.
2. You may need to add an opening double-quote and a closing double-quote 
to what you are assigning to $sql. Offhand, I think not.

Alternate approach, although you probably don't have the necessary 
permission on the server would be to
exec( mysql database_name < file_containing_table_creation_code);

I hope you find this helpful - Miles Thompson

At 10:57 AM 1/11/2002 +0000, Dave Carrera wrote:
>Hi All
>I want to create a table from a file that contains the sql to create the
>I have checked Mysql.com and have seen how to do it from telnet, but i want
>to do it from a php script.
>Can anyone please help.
>Thanks in Advance
>Dave C
>The two rules for success are:
>1. Never tell them everything you know.
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to