2016-05-13 161 views
0

我要让连接到我的在线数据库,但后来我得到这个错误:我想连接我的:在线MySQL数据库,但我得到这个错误。有人能帮我吗?

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"; 
} 

?> 

感谢您的帮助!

+0

对不起,我的意思是php。 – sander

+0

您能否删除不喜欢的内容? – sander

+0

你是否远程连接?如果是,请检查是否启用了远程连接。 –

回答

0

使用新的mysqli(),您不会在连接中添加数据库名称。

您使用mysqli_select_db($康恩,$ 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

+0

它不工作,它不关心,如果你输入你的:dbname到:$ conn。 – sander

相关问题