Prior to this see : How to create and insert a row into table in PHP
Delete a row in a table in PHP
Now we are going to see how to delete a table from a database. The code for it goes here.
<?php
//connecting to host
mysql_connect("localhost", "root", "");
//Selecting a specific Database from available databases
mysql_select_db("Example");
//Deleting a table from database
if(!mysql_query("drop table MyTable"))
{
echo 'Error'.mysql_error();
}
else
{
echo 'Deleted';
}
?>
Here we use DROP to delete a table from a database. So if you want to delete any table from a database you need to use this
mysql_query("DROP TABLE MyTable");
where ‘MyTable’ is name of the table.
See Next>> How to edit(update) a field in a table in PHP
Share this Story






7 Comments on "Delete a table from database in PHP"
you are really a good webmaster, you have done a well job on this topic!
Needed to create you that bit of observation to finally say thanks a lot again for the spectacular
can someone here tell me how to set that up?
Mr. Chrisine Wilterdink Can you specify the exact problem?
wonderful publish, very informative. I’m wondering why the other experts of this sector don’t understand this. You must continue your writing. I’m sure, you have a huge readers’ base already!
I always was interested in this subject and stock still am, thanks for putting up.
I am impressed with this website, really I am a fan.