title: Get results from from MySQL using PDO
body: <p>I'm trying to retrieve data from my table using PDO, only I can't seem to output anything to my browser, I just get a plain white page.</p>
  
  <pre><code>try {
    // Connect and create the PDO object
    $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
    $conn-&gt;exec("SET CHARACTER SET utf8");      // Sets encoding UTF-8
  
          $lastIndex = 2;
  
          $sql = "SELECT * FROM directory WHERE id &gt; :lastIndex AND user_active != '' LIMIT 20"
          $sth = $conn-&gt;prepare($sql);
          $sth-&gt;execute(array(':lastIndex' =&gt; $lastIndex));
  
          $c = 1;
          while ($row = $sth-&gt;fetch(PDO::FETCH_ASSOC)) {
              echo 'ALL STYLING ETC RESULTS HERE';
          $c++;
          }
  
    $conn = null;        // Disconnect
  }
  </code></pre>