I am new to programming and I’m totally stuck, so I thought I will ask experienced programmers for help. I created a SQL database called “books” using phpMyadmin on WAMP server. The database and its tables show properly on phpMyadmin and also on the MySQL console. I’ve been trying to connect to the database using the following PHP code:
$hs = "localhost";
$us = "heman";
$ps = "password";
$dbs = "books";
$db = new mysqli($hs, $us, $ps, $dbs);
if (mysqli_connect_error()) {
echo "Error! Could not connect to the database." . $db->connect_error . $db->connect_errno;
exit;
} else {echo "Connected to Server.";};
And, this is the error I am getting all the time:
( ! ) Warning: mysqli::__construct(): (HY000/1045): Access denied for user ‘heman’@’localhost’ (using password: YES) in C:wamp64wwwBookoramaresults.php on line 31
Error! Could not connect to the database.Access denied for user ‘heman’@’localhost’ (using password: YES) 1045.
I would really appreciate your help.
Thanks!
4
Answers
I figured out the problem. I just remembered to put it on this forum, in case it helps someone. The professionals may find it too stupid. So the problem was that my WAMP server has 2 databases, MySQL and MariaDB. And, since MariaDB was using the Port 3306, my PHP code was trying to access MariaDB using mysqli commands. Here's the solution:
There’s a solution that doesn’t require deactivating MariaDB and let’s you pick among the two whenever you want. Just right click on the WAMP icon, go to "Tools" and click on "Invert default DBMS MariaDB <-> MySQL", that should work. It will set MySQL as a default engine, change the port numbers for you and restart the services all by itself. And if it occurs that you want to switch back to MariaDB just follow the same procedure.
go to this server location C:wamp64appsphpmyadmin5.1.1 and open this file (config.inc.php) this file set some parameters
Go to your Wamp icon, right click, go to tools, then click on "use a port other than 3306 (or whatever your default port might be)".
then go back to your browser, Refresh then login with "Root" and no leave the password blank if you haven’t even set a password.