title: PHP - MySQL to PDO
body: <p>So I decided to finally move over to PDO instead of using the old mysql_</p>
  
  <p>But I noticed my site is loading slower. It's a table with 500 lines, and with my <code>mysql_</code> queries it loaded slightly faster (0.5-1 second faster).</p>
  
  <p>I wonder if it's just the way PDO works or if I've made some mistake somewhere. I did not change much from MySQL to PDO.</p>
  
  <p>Here is my original mysql_ code:</p>
  
  <pre><code>&lt;?php
                      $sql = mysql_query("SELECT * FROM rookstayers ORDER BY level DESC LIMIT 0, 500");
                      $id = 1;
                      $last_player_lvl = '';
  
                      while($row = mysql_fetch_array($sql)){
                          $name = $row['name'];
                          $level = $row['level'];
                          $world = $row['world'];
                          $account = $row['accountstatus'];
                          $status = $row['onlinestatus'];
                          $country = $row['country'];
                          $lastlogindate = $row['lastlogin'];
                          $lastlogin2 = utf8_decode($lastlogindate);
                          $lastlogin = str_replace("?", " ", $lastlogin2);
                          $onrow = '';
                          $typeServ = '';
  
                          $Date = $lastlogin;
                          $Date = substr($Date, 0, strpos($Date, " CE"));
                          $now  = date('Y-m-d');
                          $datetime1 = new DateTime($Date);
                          $datetime2 = new DateTime($now);
                          $interval = $datetime1-&gt;diff($datetime2);
  
                          $difference = $interval-&gt;format('%a days ago');
  
                          $player_name = urlencode($name);
  
                          if ($status == 1){
                              $status = 'Online';
                              $onrow = 'online';
                          } else {
                              $status = 'Offline';
                              $onrow = 'offline';
                          }
  
                          if ($account == 'Premium Account'){
                              $account = 'Premium';
                          } else {
                              $account = 'Free';
                          }
  
                          if ($world == 'Aurora' || $world == 'Aurera'){
                              $typeServ = 'activer';
                          } else {
                              $typeServ = '';
                          }
  
                      echo "&lt;tr class=" . $typeServ . "&gt;";
                          echo "&lt;td align='right'&gt;" . ( ($last_player_lvl == $row['level']) ? '' : $id ) . "&lt;/td&gt;";
                          echo "&lt;td align='center'&gt;&lt;img src='../img/flags/" . $country . ".gif'&gt;&lt;/td&gt;";
                          echo "&lt;td&gt;&lt;div class='". $onrow ."'&gt;&lt;/div&gt;&lt;/td&gt;";
                          echo "&lt;td&gt;&lt;a href='../char/" . $player_name . "' class='playerlink'&gt;" . $name . "&lt;/a&gt;&lt;/td&gt;";
                          echo "&lt;td&gt;" . $level . "&lt;/td&gt;";
                          echo "&lt;td&gt;&lt;a href='../world/" . $world ."' class='worldlink'&gt;" . $world . "&lt;/a&gt;&lt;/td&gt;";
                          echo "&lt;td&gt;"; if ($difference == 0){ echo "Today"; } elseif($difference == 1) { echo "Yesterday"; } else { echo $difference; } echo "&lt;/td&gt;";
                          echo "&lt;td&gt;" . $account . "&lt;/td&gt;";
                      echo "&lt;/tr&gt;";
  
                      // Check if there are duplicate levels, if so, give them the same rank
                      if($last_player_lvl == $row['level']){
                          $id = $id;
                      }else{
                          $id++;
                      }
  
                      $last_player_lvl = $row['level'];
                  }
                  echo "&lt;/tbody&gt;";
              echo "&lt;/table&gt;";
              ?&gt;
  </code></pre>
  
  <p>and here is my PDO code</p>
  
  <pre><code>&lt;?php
  
                  $sql = 'SELECT * FROM rookstayers ORDER BY level DESC LIMIT 0, 500';
                  $id = 1;
                  $last_player_lvl = '';
  
                  foreach ($db-&gt;query($sql) as $row) {
                      $name = $row['name'];
                      $level = $row['level'];
                      $world = $row['world'];
                      $account = $row['accountstatus'];
                      $status = $row['onlinestatus'];
                      $country = $row['country'];
                      $lastlogindate = $row['lastlogin'];
                      $lastlogin2 = utf8_decode($lastlogindate);
                      $lastlogin = str_replace("?", " ", $lastlogin2);
                      $onrow = '';
                      $typeServ = '';
  
                      $Date = $lastlogin;
                      $Date = substr($Date, 0, strpos($Date, " CE"));
                      $now  = date('Y-m-d');
                      $datetime1 = new DateTime($Date);
                      $datetime2 = new DateTime($now);
                      $interval = $datetime1-&gt;diff($datetime2);
  
                      $difference = $interval-&gt;format('%a days ago');
  
                      $player_name = urlencode($name);
  
                      if ($status == 1){
                          $status = 'Online';
                          $onrow = 'online';
                      } else {
                          $status = 'Offline';
                          $onrow = 'offline';
                      }
  
                      if ($account == 'Premium Account'){
                          $account = 'Premium';
                      } else {
                          $account = 'Free';
                      }
  
                      if ($world == 'Aurora' || $world == 'Aurera'){
                          $typeServ = 'activer';
                      } else {
                          $typeServ = '';
                      }
  
                      echo "&lt;tr class=" . $typeServ . "&gt;";
                      echo "&lt;td align='right'&gt;" . ( ($last_player_lvl == $row['level']) ? '' : $id ) . "&lt;/td&gt;";
                      echo "&lt;td align='center'&gt;&lt;img src='../img/flags/" . $country . ".gif'&gt;&lt;/td&gt;";
                      echo "&lt;td&gt;&lt;div class='". $onrow ."'&gt;&lt;/div&gt;&lt;/td&gt;";
                      echo "&lt;td&gt;&lt;a href='../char/" . $player_name . "' class='playerlink'&gt;" . $name . "&lt;/a&gt;&lt;/td&gt;";
                      echo "&lt;td&gt;" . $level . "&lt;/td&gt;";
                      echo "&lt;td&gt;&lt;a href='../world/" . $world ."' class='worldlink'&gt;" . $world . "&lt;/a&gt;&lt;/td&gt;";
                      echo "&lt;td&gt;"; if ($difference == 0){ echo "Today"; } elseif($difference == 1) { echo "Yesterday"; } else { echo $difference; } echo "&lt;/td&gt;";
                      echo "&lt;td&gt;" . $account . "&lt;/td&gt;";
                      echo "&lt;/tr&gt;";
  
                      // Check if there are duplicate levels, if so, give them the same rank
                      if($last_player_lvl == $row['level']){
                          $id = $id;
                      }else{
                          $id++;
                      }
  
                      $last_player_lvl = $row['level'];
                  }
                  echo "&lt;/tbody&gt;";
                  echo "&lt;/table&gt;";
                  ?&gt;
  </code></pre>
  
  <p>maybe something to improve when it comes to the PDO part?</p>