I am new to PHP. I am trying to connect to a MySQL database using mysqli. I created a new user, and it didn't connect and threw the access denied error. I gave database-specific grant in PHPMyAdmin, but still throws error. Then I tried with the root user as well, and it still throws the same error. Here's my code:
<?php
// create mysqli connection
$conn = new mysqli('localhost', 'root', '', 'dbname');
// check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo 'Connected to the database successfully!';
I don't understand why that is happening. Please help me! Thanks in advance...