1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

truncate mysql table script

Discussion in 'MySQL' started by muppethunter, Apr 9, 2008.

  1. #1
    I am looking for a script that I can call up via a url and truncate or delete the data from a table. I searched the forum and googled it and came up with this but do not know how to impliment this into an html or php document thats user friendly.


    [PHP]mysql_connect($Host,$UserName,$PassWord);
    @mysql_select_db($DataBase) or die(mysql_error());
    
    $query="TRUNCATE --TABLENAME--";
    
    mysql_query($query);
    mysql_close();[PHP]
    Code (markup):

     
    muppethunter, Apr 9, 2008 IP
  2. Travis

    Travis Peon

    Messages:
    539
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That would basically work right out of the box, but it obviously needs the $Host, $UserName, and $PassWord variables to connect to your MySQL server.

    the proper query should be "truncate files;" if your table name was files.

    Just be aware that that will delete ALL of the data, if you want to remove certain rows, you should use the DELETE command (look it up in the MySQL manual).

    Saving that entire thing (with the right variables) as a .php document (IE. truncate.php) and uploading it to the server will allow you to call the url (http://www.site.com/truncate.php) and it will delete everything.

    Just be aware that if you have data on that database which you need, and you make that file available to everyone to visit, your data will be destroyed every time someone calls the page, so be careful =).
     
    Travis, Apr 9, 2008 IP
  3. muppethunter

    muppethunter Guest

    Messages:
    123
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That doesn't work. It keeps giving me an access denied error. I know I have the right username , DB, and password. Any ideas.

    Thanks for the help.
     
    muppethunter, Apr 9, 2008 IP
  4. muppethunter

    muppethunter Guest

    Messages:
    123
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the help. I got it to work using this. Obviously you need to insert your database name, database table name, password and host.

    <?php
    MYSQL_CONNECT('host','database_username','database_password');
    @mysql_select_db("database_name") or die(mysql_error());
    
    $query="TRUNCATE table_name";
    
    mysql_query($query);
    mysql_close()
    ?>
    
    Code (markup):
     
    muppethunter, Apr 9, 2008 IP