MySQL vs PDO execution time I'm having some issues understanding why PDO is 6X slower executing a query than the depreciated MySQL query function. Here's my code:

$conn = new PDO('mysql:host=localhost;dbname=work', 'root', 'Montreal');

protected function query_s($table, $col = '*', $where_col , $where, $return_col)
{

              $q = $conn-&gt;query("SELECT $col FROM $table WHERE $where_col='".$where."' LIMIT 1");
              $f = $q-&gt;fetch();
              $result = $f[$return_col];
              return $result;

}


Which retrieves 1 piece of information for a specific column. 

The old code:

protected function query_s($table, $col = '*', $where_col , $where, $return_col)
{

    $SQL = mysql_query("SELECT $col FROM ".$table." WHERE $where_col='$where' LIMIT 1") or die(mysql_error());
            $data = mysql_fetch_array($SQL);
            $this-&gt;query_rows = mysql_num_rows($SQL);

            return $data[$return_col];  
}


As soon as I run the PDO version in a while loop through a database search (user tries to find something), it takes almost 6 seconds to retrieve 50 rows... Normally, it would take around 0.02 seconds with the MySQL function

I'm fairly new with PDO and I'm trying to write new code with it. I'm missing something here.
Change your connection string from host=localhost to host=127.0.0.1, for some reason PDO is slow at resolving the host name, just when using PDO always use the IP address of the server.

Also why are you fetching one row at a time when you need 50?