使用此代码连接到 localhost 时,我收到一条错误消息。我无法连接到 MYSQL,我不知道为什么:
<?php
//connect
$link = mysqli_connect("$localhost", "$root", "$password", "$database");
if (!$link)
{
$output = 'Unable to connect to the database server.';
include 'output.html.php';
exit();
}
if (!mysqli_set_charset($link, 'utf8'))
$output = 'Unable to set database connection encoding.';
include 'output.html.php';
exit();
}
if (!mysqli_select_db($link, '$database'))
{
$output = 'Unable to locate the Teamster database.';
include 'output.html.php';
exit();
}
$output = 'Database connection established. ';
include 'output.html.php';
?>
我收到此错误消息。这是我刷新页面时在我创建的表单上方填充的内容。这是连接问题还是编码问题?
//check connection //if (mysqli_connect_errno($con)) // { echo "Failed to connect to MySQL: " . mysql_connect_error(); // } //