简体   繁体   中英

CPanel Database connection error

I recently switched to CPanel, and ever since then, I've had issues. I'm having an issue connecting to a database. I created it in CPanel, with the hypothetical username 'root' and password '123' . I have a file /scripts/dbh.php and a file /index.php . Here are the contents.

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)
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>

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

Check your last parameter for 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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