我使用 MySQL Workbench 来运行查询。运行它们几乎不需要任何时间。但是,当我通过 PDO 连接到数据库时,连接需要超过一秒钟!为什么?
<?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;
这输出:
1008.975982666