title: PHP PDO - can connect but query not working
body: <p>I want to wean myself from the teat of the old mysql extension and am just doing a test PDO connection and simple query on a table in a database. I seem to be able to connect, ('connection successful' echoes out) but that's where the good times end. I have spent way too much time now just trying to get started with PDO.</p>
  
  <pre><code>&lt;?php
  $host = 'localhost';
  $port = '3306'; 
  $username = 'user';
  $password = 'blabla';
  $database = 'workslist';
  
  try {
      $db = new PDO("mysql:host=$host; port = $port; dbname = $database", $username, $password);
      echo 'connection successful&lt;br /&gt;';
  
      $query = 'SELECT * FROM main';
      $statement = $db-&gt;prepare($query);
      $statement-&gt;execute();
      $results = $statement-&gt;fetchAll();
      $statement-&gt;closeCursor();      
  
      foreach($results as $r){
              echo $r['work'] . '&lt;br /&gt;';
      }
  
  } catch (PDOException $e) {
      echo 'Error!: ' . $e-&gt;getMessage() . '&lt;br /&gt;';
      die();
  } 
  ?&gt;
  </code></pre>
  
  <p>Is there anything wrong with the above?</p>
  
  <p>The database name is 'workslist', the table name is 'main', and 'work' is one of the columns in that table. The PHP version I'm using is 5.3.4, and am using wamp on win7. I ran <code>phpinfo()</code> and under the PDO heading, the PDO drivers mysql, sqlite are enabled. To be sure the database and table actually exist I've tried it with MySQL and can return rows with the old <code>mysql_fetch_array()</code> method. I've checked the php.ini file to make sure the "extension=php_pdo..." lines are all uncommented. </p>
  
  <p>cheers</p>