title: mysql_ to pdo: did i do it right?
body: <p><a href="https://i.stack.imgur.com/CbmCi.png" rel="nofollow noreferrer"> (browseroutput.jpg) </a></p>
  
  <p>I just switched a old <code>mysql_* from</code> a old tutorial to PDO and wanted to know if im doing it right.
  I did'nt get the <code>mysql_*</code> and PDO, are they drivers or just different variants to fetch data?</p>
  
  <p>My code work as it should but im kinda sceptical that it work because im a beginner.</p>
  
  <pre><code>  &lt;?php
    // New PDO variant   
  
    try {
       $user = "user";
       $pass = "";
  
       $pdo = new PDO('mysql:host=localhost;dbname=testdb', $user, $pass);
  
       //build query
       $age = $_GET['age'];
       $sex = $_GET['sex'];
       $wpm = $_GET['wpm'];
  
       $query = "SELECT * FROM ajax_example WHERE sex = '$sex'";
  
       if(is_numeric($age))
       $query .= " AND age &lt;= $age";
  
       if(is_numeric($wpm))
       $query .= " AND wpm &lt;= $wpm";
  
       $stmt = $pdo-&gt;prepare($query);
  
       $display_string = "&lt;table&gt;";
       $display_string .= "&lt;tr&gt;";
       $display_string .= "&lt;th&gt;Name&lt;/th&gt;";
       $display_string .= "&lt;th&gt;Age&lt;/th&gt;";
       $display_string .= "&lt;th&gt;Sex&lt;/th&gt;";
       $display_string .= "&lt;th&gt;WPM&lt;/th&gt;";
       $display_string .= "&lt;/tr&gt;";
  
       $stmt-&gt;execute(array('name' =&gt; $name));
  
       foreach ($stmt as $row) {
          $display_string .= "&lt;tr&gt;";
          $display_string .= "&lt;td&gt;$row[name]&lt;/td&gt;";
          $display_string .= "&lt;td&gt;$row[age]&lt;/td&gt;";
          $display_string .= "&lt;td&gt;$row[sex]&lt;/td&gt;";
          $display_string .= "&lt;td&gt;$row[wpm]&lt;/td&gt;";
          $display_string .= "&lt;/tr&gt;";
       }
  
       echo "Query: " . $query . "&lt;br /&gt;";
  
       $display_string .= "&lt;/table&gt;";
       echo $display_string;
       $dbh = null;
  
    } catch (PDOException $e) {
       print "Error!: " . $e-&gt;getMessage() . "&lt;br/&gt;";
       die();
    }
    ?&gt;
  </code></pre>