Delete all rows from a table

avatar December 25, 2011 by: 13

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
Categories
Php  
Tags
Add a Comment on "Delete all rows from a table"

    13 Comments on "Delete all rows from a table"

  1. 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.

  2. Bookmarked! Thanks for an amazing post, will read your others posts.

  3. avatar Ivan Soose says:

    Bookmarked! Thanks for an amazing post, will read your others posts.

  4. 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

  5. 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.

  6. avatar Joey Fishman says:

    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.

  7. avatar Cindi Juel says:

    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.

  8. avatar Merle Tenor says:

    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.

  9. avatar fitness says:

    some really interesting points you have written.

  10. I really like your blog.I often learn new information from here.Thank you for your help!

  11. avatar fotografia says:

    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.

  12. avatar zoomagazin says:

    Thank you for this post.

Follow us

About Techdigit

Tech Digit comprises of many authors but the CEO of techdigit is Sriram who is an internet Marketer and Entrepreneur.