Re: Adding tables to mySQl database
| From: | David Robley | Date: | Fri, 04 Aug 2000 07:39:51 +0000 |
| Subject: | Re: Adding tables to mySQl database | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-10083@lists.php.net to get a copy of this message | ||
On 4 Aug, Thomas Edison Jr. wrote:
> Can we add new tables with the "create table"
> statement into an already existing database with
> tables? Or do we need to give some other syntax? It's
> not happenin at my server. The following code is
> executing without error - but no table is being
> generated.
>
> the code :
> <?php
> $db = mysql_connect("localhost","root");
> mysql_select_db("mydb",$db);
>
> $sql = "Create table chat (session varchar(20), poster
> varchar(30), post text, time bigint(20), text_color
> varchar(20), id int(11) auto_increment, PRIMARY
> KEY(id))";
>
> $result = mysql_query($sql);
> echo "Thank you! Your information has been
> entered.\n";
> ?>
>
If it doesn't work, try using mysqlerror() after the database update.
You may not have appropriate permissions to create a table in that
database, for instance.
> Also, how can we delete a table and it's contents
> using a php script?
$sql = "DROP TABLE tablename";
You can use any of the mysql SQL in a mysql_query using PHP; assuming
you have the appropriate rights set up under mysql for the user issuing
the commands. And note that root has no special rights as in real shell
:-)
And now I might go home....
Cheers
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA