0

I keep receiving an error of "Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO)" when trying to connect to mysql database using mysqli. I have created a simple php program to connect to a database in mysql using sqli(see below). I am currently using wamp64 and have been trying to solve this error for a very long time. At current I have phpmyadmin login username as root and not requiring a password, I do not have an issue when logging into phpmyadmin, just am not able to connect to any of the databases I have created. When researching this error I have found nothing similar to what I am experiencing. Is it possible something could be wrong with my configuration settings? I am also using Windows 10 operating system.

<?php  

$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "newestdatabase";

$conn = mysqli_connect($hostname, $username, $password, $dbname);


if ($conn) {

    echo "Connection success.";
}

?>

1 Answers1

0

This error appears because you have passed invalid credentials (user name and/or password or maybe the hostname) when trying to connect to the database. You have to check the valid credentials by yourself. If you use phpmyadmin it should be in tab "User Accounts".

see this reference may help you https://dev.mysql.com/doc/refman/5.7/en/creating-accounts.html

  • I am now receiving error stating "Warning: mysqli_connect(): (HY000/1049): Unknown database". I created the database already and it exists in mysql so why would this error occur? I created a test database before and was able to connect to it just fine. – Soccerplayer97 Dec 24 '19 at 21:42
  • the error is localhost should be localhost:3308, have to specify port name for wamp. – Soccerplayer97 Dec 25 '19 at 01:19