3

I use MySQL Workbench to run queries. It takes literally no time at all to run them. However, when I connect to the database via PDO, it takes over one second to connect! Why?

<?php

$host = "localhost";
$db = "localhost";
$user = "root";
$pass = "";

$mtime = explode(" ",microtime());
$starttime = $mtime[1] + $mtime[0];

$conn = new PDO("mysql:host=$host;dbname=$db",$user,$pass);

$mtime = explode(" ",microtime());
$totaltime = (($mtime[1] + $mtime[0]) - $starttime);
echo $totaltime * 1000;

This outputs:

1008.975982666
Student of Hogwarts
  • 1,108
  • 3
  • 14
  • 28

1 Answers1

9

On windows vista and newer use 127.0.0.1 instead of localhost.

dev-null-dweller
  • 29,274
  • 3
  • 65
  • 85