title: Call to a member function exec() on a non-object when doing PDO::exec()
body: <p>I am working on a PHP script to export/import some database rows from one DB to another.</p>
  
  <p>So far I got this function to make sure the destination table is empty before putting new rows in there:</p>
  
  <pre><code>function truncateTable($conn, $tblname)
  {
      echo "Truncating..";
      $query = $conn-&gt;exec("TRUNCATE TABLE $tblname") or die("failed!");
      echo "Truncated table $tblname!";
  }
  </code></pre>
  
  <p>However, this is giving me this error:</p>
  
  <pre><code>Call to a member function exec() on a non-object
  </code></pre>
  
  <p>The connectionstring that gets passed to the function in <code>$conn</code> looks like this:</p>
  
  <pre><code>$con2 = new PDO("mysql:host=$dbs2;dbname=$dbd2",$dbu2,$dbp2);
  </code></pre>
  
  <p>I call the function like this:</p>
  
  <pre><code>truncateTable($con2, "users");
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>I am just learning PDO, so forgive me if this is a very basic question.</p>