Need Help with PHP Database Connection Issues

hellmmithha

Nuovo Utente
12 Dic 2024
1
0
1
Hi everyone,

I'm relatively new to PHP and I've been working on a simple web project where I need to connect to a MySQL database. I've followed a few tutorials, but I'm running into an issue when trying to establish a connection using mysqli.

Here's the code I've been using:

Codice:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDatabase";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

However, I keep getting an error that says "Connection failed: Access denied for user 'root'@'localhost'". I've double-checked the credentials, and the database exists, but I'm still unable to connect.

Has anyone encountered this issue before? If so, what should I look for to resolve it? Any help or insights would be greatly appreciated!

Thanks in advance!

Respected community member!
 

Discussioni simili