Prior to this see : How to create and insert a row into table in PHP
Delete a row in a table in PHP
Now that we have learnt how to delete a specified field from a table we are going to see how to delete all rows from the table. Here’s the code for it.
<?php
//connecting to host
mysql_connect("localhost", "root", "prashanth");
//Selecting a specific Database from available databases
mysql_query("create database Example");
mysql_select_db("Example");
//Deleting a rows
if(!mysql_query("delete from MyTable"))
{
echo 'Error'.mysql_error();
}
else
{
echo 'Deleted';
}
?>
The only difference is that we specify ‘where’ keyword to delete a specific field, but here we don’t specify any keyword so it deletes all fields from the table at once.
Also see:: How to Delete a table from database in PHP
Share this Story






13 Comments on "Delete all rows from a table"
There are certainly a lot of details like that to take into consideration. That is a great point to bring up. I offer the thoughts above as general inspiration but clearly there are questions like the one you bring up where the most important thing will be working in honest good faith. I don?t know if best practices have emerged around things like that, but I am sure that your job is clearly identified as a fair game. Both boys and girls feel the impact of just a moment’s pleasure, for the rest of their lives.
Bookmarked! Thanks for an amazing post, will read your others posts.
Bookmarked! Thanks for an amazing post, will read your others posts.
Sharp thinking! Thanks for the ansewr.
I just couldn’t give your blog prior to recommending which i in fact adored the usual articles a homeowner give onto your friends? Is to returning continuously so as to investigate cross-check innovative content
Hiya, I’m really glad I’ve found this information. Today bloggers publish just about gossip and internet stuff and this is really frustrating. A good web site with exciting content, this is what I need. Thank you for making this website, and I’ll be visiting again. Do you do newsletters? I Cant find it.
Im a huge fan already, man. Youve done a brilliant job making sure that people understand where youre coming from. And let me tell you, I get it. huge stuff and I cant wait to check out more of your websites. What youve got to say is important and needs to be read.
An engrossing communication is worth note. I guess that you should make many on this topic, it power not be a bias topic but generally people are not enough to utter on much topics.
Whoah your blog will be spectacular i actually honestly just like examining your own articles or blog posts. Carry on the great art! You understand, plenty of persons are searching rounded for this info, you may facilitate them dramatically.
some really interesting points you have written.
I really like your blog.I often learn new information from here.Thank you for your help!
Finally, a problem that I’m passionate about. I have looked for details of this caliber for that final a number of hrs. Your internet site is significantly appreciated.
Thank you for this post.