[SOLVED] How to create Mysql table using PHP script?
Moderator: General Moderators
-
sisleysusie
- Forum Newbie
- Posts: 16
- Joined: Wed Jan 14, 2004 9:44 pm
[SOLVED] How to create Mysql table using PHP script?
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.
-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
Query this.
Code: Select all
create table table1
(name varchar(60),
firstname varchar(15))-
sisleysusie
- Forum Newbie
- Posts: 16
- Joined: Wed Jan 14, 2004 9:44 pm
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
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());
$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());
-
sisleysusie
- Forum Newbie
- Posts: 16
- Joined: Wed Jan 14, 2004 9:44 pm
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
$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
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
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
See this link for more info.
http://ca3.php.net/manual/en/function.m ... tables.php
-
sisleysusie
- Forum Newbie
- Posts: 16
- Joined: Wed Jan 14, 2004 9:44 pm