我想连接到我的在线数据库,但后来我收到了这个错误:
警告:mysqli :: mysqli():( HY000 / 2002):连接尝试失败,因为"关联方错误如果答案在一定时间后,成本连接失败,因为"南方邦联主持人没有回应。 C:\ wamp \ www \ array在第8行添加db \ 222.php
这是我的代码:
?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";
}
?>
感谢您的帮助!
答案 0 :(得分:0)
使用新的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