2017-01-21 92 views
-1

最近我切换到的cPanel,并从那时起,我有问题。我遇到连接到数据库的问题。我在CPanel中创建了它,假设用户名为'root',密码为'123'。我有一个文件/scripts/dbh.php和一个文件/index.php。这里是内容。的cPanel数据库连接错误

dbh.php:

<?php 
// Database Handler 
$db_name = 'hughchalmers'; 
$servername = "localhost"; 
$username = "root"; 
$password = "123"; 
$table_name = 'accounts'; 
$conn = mysqli_connect($servername, $username, $password, $db_name) or   die('Cannot connect to database. Contact an admin'); 
?> 

(hughchalmers是一个数据库,账户是一个表)
的index.php:

<?php 
include($_SERVER['DOCUMENT_ROOT'].'/memedictionary/scripts/header.php'); 
include($_SERVER['DOCUMENT_ROOT']. '/memedictionary/scripts/dbh.php') 
?> 
<head> 
<title>Login</title> 
</head> 
<body> 

</body> 

有什么问题吗?它只是随着我设置的消息而死亡(无法连接到数据库,请联系管理员)。道歉,我很新的MySQL和的cPanel

+0

第四个参数是数据库,不是表。是'accounts'一个数据库或表? – chris85

+0

accounts是数据库中的一个表。编辑的问题,仍然不起作用。 –

+1

使用连接错误功能获取更多信息。 http://php.net/manual/en/mysqli.connect-error.php – chris85

回答

0

检查mysqli_connect)的最后一个参数(。看起来你指的是一个表,而不是它必须是数据库名称,或者它只是一个变量名,但实际上是在传递一个数据库名?

+0

编辑问题,仍然不起作用 –