Page 1 of 1

[SOLVED] How to create Mysql table using PHP script?

Posted: Wed Jan 14, 2004 9:44 pm
by sisleysusie
Hi all, i am very new in using PHP and MySQL. I am wondering whether i can create MySQL table using PHP script since there is no mysql_query that i can find to create tables using PHP script. Thanks in advance.

Posted: Wed Jan 14, 2004 10:02 pm
by Straterra
Query this.

Code: Select all

create table table1
(name varchar(60),
firstname varchar(15))

Posted: Wed Jan 14, 2004 10:46 pm
by sisleysusie
Let's say i am using coding like below:


$query = "CREATE table email ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), email VARCHAR (70))";
mysql_query($sql,$link) or die (mysql_error());

I am creating one table email. Can i create another table in the same $query? Thanks

Posted: Wed Jan 14, 2004 11:11 pm
by microthick
Just add a semi-colon after your first create table statement and write another one.

$query = "CREATE table email ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), email VARCHAR (70)); CREATE table email2 ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), email VARCHAR (70));";
mysql_query($sql,$link) or die (mysql_error());

Posted: Thu Jan 15, 2004 12:47 am
by sisleysusie
Thanks for the replies. How can i know that the tables have been created? I tried to check by using this code


$query = "SELECT id FROM individual_general_info WHERE id=1";
$result = mysql_query($query);
if(!empty ($result["id"]))
{
echo $result["id"]; }
else
echo "Table is exist but contains no data";

Can i know whether the table is exist by using that code? Thank you

Posted: Thu Jan 15, 2004 1:37 am
by microthick
You can list all tables by using the command mysql_list_tables().

See this link for more info.

http://ca3.php.net/manual/en/function.m ... tables.php

Posted: Fri Jan 16, 2004 2:58 am
by sisleysusie
Thanks microthick. I really appreciate your help