简体   繁体   English

CPanel 数据库连接错误

[英]CPanel Database connection error

I recently switched to CPanel, and ever since then, I've had issues.我最近切换到 CPanel,从那时起,我就遇到了问题。 I'm having an issue connecting to a database.我在连接到数据库时遇到问题。 I created it in CPanel, with the hypothetical username 'root' and password '123' .我在 CPanel 中创建了它,假设用户名'root'和密码'123' I have a file /scripts/dbh.php and a file /index.php .我有一个文件/scripts/dbh.php和一个文件/index.php Here are the contents.以下是内容。

dbh.php: 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 is a database, accounts is a table) (hughchalmers 是一个数据库,accounts 是一个表)
index.php:索引.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>

What's the issue here?这里有什么问题? It just dies with that message I set (Cannot connect to database. Contact an admin).它只是随着我设置的消息而消失(无法连接到数据库。联系管理员)。 Apologies, I'm very new to MySQL and CPanel抱歉,我对 MySQL 和 CPanel 很陌生

Check your last parameter for mysqli_connect().检查 mysqli_connect() 的最后一个参数。 Looks like you're referring to a table when instead it must be the database name or is it just a variable name but you're passing a database name actually?看起来您指的是一个表,而它必须是数据库名称还是只是一个变量名称,但实际上您传递的是一个数据库名称?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM