gpt4 book ai didi

php - 我想连接我的 : online MySQL database, 但收到此错误。有人能帮我吗?

转载 作者:行者123 更新时间:2023-11-29 21:01:12 27 4
gpt4 key购买 nike

我想连接到我的在线数据库,但随后出现此错误:

Warning: mysqli :: mysqli (): ( HY000 / 2002 ): A connection attempt failed because the " Related party Incorrectly If the answer after a certain time , of the costs Connection failed because " the Confederate host has not responded . C: \ wamp \ www \ array Add in db \ 222.php on line 8

这是我的代码:

?php

$servername = "db.tapdeleest.nl"; $username = "***"; $password = "***"; $dbname = "***";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else
{
echo "nice";
}

?>

感谢您的帮助!

最佳答案

使用 new mysqli(),您无需在连接中添加数据库名称。

您使用 mysqli_select_db($conn, $dbname)

<?php

$servername = "db.tapdeleest.nl"; $username = "***"; $password = "***"; $dbname = "***";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else
{
echo "nice";
mysqli_select_db($conn, $dbname);
}

?>

只是建议:尝试一下pdo,我觉得pdo更容易。 http://www.w3schools.com/php/php_mysql_connect.asp

关于php - 我想连接我的 : online MySQL database, 但收到此错误。有人能帮我吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37214285/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com