dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: PDO table truncate

  1. #1
    Join Date
    Nov 2013
    Posts
    17

    PDO table truncate

    Hi guys. I have following code to delete particular row from a table based on the title. But how can I delete all data from the table?

    PHP Code:
    <?php
    require 'connpdo.php';
    $naslov $_POST['naslov'];
    #DELETE DATA
    //delete some data
    $sqlInsert 'DELETE FROM bloging WHERE title=:title';
    $preparedStatement $conn->prepare($sqlInsert);
    $preparedStatement->execute(array(':title' => $naslov));


    //REDIRECT TO HOME PAGE
    header('Location: http://localhost/ITAPHP/index.php');
    ?>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,306
    Simplest and most efficient way, if it's okay that it will be an implicit commit (at least assuming recent versions of MySQL):
    PHP Code:
    $conn->query("TRUNCATE TABLE blogging"); 
    If you are using transactions and don't want a commit at that point, then:
    PHP Code:
    $conn->query("DELETE FROM blogging"); 
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Nov 2013
    Posts
    17
    Quote Originally Posted by NogDog View Post
    Simplest and most efficient way, if it's okay that it will be an implicit commit (at least assuming recent versions of MySQL):
    PHP Code:
    $conn->query("TRUNCATE TABLE blogging"); 
    If you are using transactions and don't want a commit at that point, then:
    PHP Code:
    $conn->query("DELETE FROM blogging"); 
    Thank you!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles