skip to Main Content

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!

enter image description here

4

Answers


  1. Chosen as BEST ANSWER

    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:

    1. Right-click on WAMP icon at the bottom right of the screen.
    2. Go to 'Wamp Settings'.
    3. Remove the check from 'Allow MariaDB'.
    4. Change the port number of MySQL to 3306. (Left click wamp icon -> scroll over MySQL -> Click my.ini -> Press "Ctr + f" and search "port" -> change port number to 3306 at all the 3 places in the file -> Save the file.)
    5. Restart all the services and there you go....!

  2. 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.

    Login or Signup to reply.
  3. go to this server location C:wamp64appsphpmyadmin5.1.1 and open this file (config.inc.php) this file set some parameters

    $cfg['Servers'][$i]['host'] = 'localhost'; $cfg['Servers'][$i]['port'] = 3306; 
    
    Login or Signup to reply.
  4. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search