title: Empty table before insert pdo
body: <p>I have a script for importing data from rss files, and I want to empty my table before insert, so I don't have any old entries in my database, but I can't get the syntax right, because nothing gets deleted.</p>
  
  <p>Here is what I'm trying:</p>
  
  <pre><code>try {
      $db-&gt;beginTransaction();
  
      $stmt = $db-&gt;prepare("DELETE FROM $table");
  
      $stmt = $db-&gt;prepare("INSERT INTO $table(id,name) VALUES(:id,:name)ON DUPLICATE KEY UPDATE name=:name");
      $stmt-&gt;execute(array(':id' =&gt; $id, ':name' =&gt; $name));
  
      $db-&gt;commit();
  } catch(PDOException $ex) {
      //Something went wrong rollback!
      $db-&gt;rollBack();
      echo $ex-&gt;getMessage();
  }    
  </code></pre>
  
  <h1>EDIT</h1>
  
  <p>I have tried with Truncate, but thought I needed delete since truncate does not empty/delete anything:</p>
  
  <pre><code>try {
      $db-&gt;beginTransaction();
  
      $stmt = $db-&gt;prepare("TRUNCATE TABLE $table");
  
      $stmt = $db-&gt;prepare("INSERT INTO $table(id,name) VALUES(:id,:name)ON DUPLICATE KEY UPDATE name=:name");
      $stmt-&gt;execute(array(':id' =&gt; $id, ':name' =&gt; $name));
  
      $db-&gt;commit();
  } catch(PDOException $ex) {
      //Something went wrong rollback!
      $db-&gt;rollBack();
      echo $ex-&gt;getMessage();
  }    
  </code></pre>