MySQL php 连接失败

MySQL php connect failure

我有以下 php 代码:

<?php
$con=mysqli_connect("server19.0hosting.org","user","password","dbname");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM dbtable");

echo "<table border='1'>
<tr>
<th>Nume</th>
<th>Teme facute</th>
<th>Teme nefacute</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Nume'] . "</td>";
echo "<td>" . $row['Teme facute'] . "</td>";
echo "<td>" . $row['Teme nefacute'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

当我 运行 它在线时,我收到以下消息:

Warning: mysqli_connect(): (28000/1045): Access denied for user 'u536268762_alex'@'srv19.main-hosting.com' (using password: YES) in /home/u536268762/public_html/index.html on line 2 Failed to connect to MySQL: Access denied for user 'u536268762_alex'@'srv19.main-hosting.com' (using password: YES)

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /home/u536268762/public_html/index.html on line 9

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u536268762/public_html/index.html on line 18

Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in /home/u536268762/public_html/index.html on line 28

有谁能帮帮我吗? 另外,我在用户之前写的主机名是否正确?

您的陈述有误。

mysqli_connect("server19.0hosting.org","user","password","dbname");

mysli_connect("hostname", "username", "password", "databasename");

检查此参数是否正确(与向您提供此详细信息的人员或管理员核实) server19.0hosting.org(hostname) 是正确的 用户(用户名)是正确的 密码(密码)是正确的 dbname(databasename) 是正确的

虽然您应该提供一些主机信息,但我会假设某些事情(如有必要)并在此处输入一些内容。

  1. 如果你的 php 脚本在同一台服务器上,它有数据库(所有共享服务中最常见的东西),那么你可以简单地使用本地主机,例如;

    $con=mysqli_connect("localhost","user","password","dbname");

  2. 访问被拒绝的可能原因是:

    • 用户名或密码错误。
    • 用户名没有被授予连接数据库的权限。 (您通常在创建新数据库时执行此操作。)