【发布时间】:2021-03-21 06:27:17
【问题描述】:
这是我第一次使用 PHP。我在 Mac 上使用 XAMPP。
MySQL、Apache 和 localhost:8080 现在都在工作。 我创建了这个名为 test.php 的文件并将其保存在 lampp/htdocs 中:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Connection</title>
</head>
<body>
<?php
$servername = "localhost:8080";
$username = "root";
$password = "root";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error($conn));
}
else
{
echo "Connected successfully";
}
?>
</body>
</html>
但是,当我转到 localhose:8080/test.php 时,会打开一个空白页面,但没有显示任何内容
【问题讨论】:
-
使用这个来开启错误显示。 ini_set('display_errors', 1); ini_set('display_startup_errors', 1);错误报告(E_ALL);并检查您的网络服务器错误日志。
-
我试过了。这是因为我不能在 'mysqli_connect_error()' 中添加参数但是,现在它显示我
连接失败:连接被拒绝
你知道为什么会发生这种情况 -
localhost:8080是您的网络服务器,MySQL 端口通常是 3306