php中的SELECT查询:响应太晚

时间:2018-07-17 11:42:25

标签: php mysql

所有其他具有相同数据库连接的页面都可以正常工作,但是此页面需要10-15分钟的加载时间。

它产生正确的输出,但是花费很长时间,尽管该表“ user”只有2条记录。

我错过了什么东西或犯了一些错误吗?

$conn = mysqli_connect("localhost","root","","myprojectdatabase");

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$result = mysqli_query($conn, "SELECT * FROM user ");

while( false !== ($row = mysqli_fetch_assoc($result))){
    echo "<pre>";
    echo $row['username'];
}
$conn->close();

1 个答案:

答案 0 :(得分:1)

尝试使用下面的代码,看看它是否对您有用

   $conn = mysqli_connect("localhost","root","","myprojectdatabase");
   if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
   }
   $result = mysqli_query($conn, "SELECT * FROM user");
   while( false !=($row = mysqli_fetch_assoc($result)))
   {
     echo"<pre>";
     echo $row['username'];
   }
   $conn->close();