0

So I made an app which has a log in script and I'm using a WAMP server. I want to put users into the MySql database. When I run my script using a log in form I get this error: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO). I don't know whats the problem.

I know that many commenter have told me that the user has a password. I know that. The problem is that even if I use the password in my password variable(as you can see in my code; I'm using a connect function to connect to the database). It still doesn't connect.

public function connect()
{
    try {
        $username = "root";
        $password = "";
        $db = new PDO('mysql:host=localhost;dbname=readersnewcenter', $username, $password);
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        return $db;
    } catch (PDOException $e) {
        print "Error: " . $e->getMessage() . "<br/>";
        die();
        // throw exception

    }
    
  • 3
    Please don’t include images of code. It’s much faster and less effort to paste your code as text, anyway. Potential answers should not have to hand-transcribe what you have so far to run it on their own machines. – esqew Nov 06 '21 at 19:33
  • The `Access denied for user 'root'@'localhost' (using password: NO)` means: Your user has a password, but you try connect without password – a55 Nov 06 '21 at 19:53
  • Its the default on in VS Code. Very nice :) – état de choses Nov 06 '21 at 19:54
  • I know that Im not supposed to use a password but when I put one in the Connect function is doesn't do anything. I get the same error. – état de choses Nov 06 '21 at 19:55
  • Also the root user always has a password in this WAMP version. – état de choses Nov 06 '21 at 20:07
  • how do i change the using password to no? – état de choses Nov 06 '21 at 20:08
  • you can change the password like https://stackoverflow.com/a/27218173 – a55 Nov 06 '21 at 20:17
  • [Here's the reason why you shouldn't upload text as image](https://meta.stackoverflow.com/a/285557/13447). Edit your question to contain all the information in text form. Also see [ask] - and it seems that the problem is solved, as the error message clearly stated what was wrong. – Olaf Kock Nov 07 '21 at 10:48
  • The error is saying that your `root` user account has a password but you are not using it on the connection. You cannot just make one up and try it, there is a specific password which you have to use!! – RiggsFolly Nov 07 '21 at 15:38

0 Answers0