Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
Posted by: rpjd (37.228.250.---)
Date: November 18, 2021 01:06PM

1 Windows11 64 bit
2 wampserver3.2.0_x64
3 2.4.41
4 7.3.12
5 8.0.18
6 Green
8 Yes
8a No
9 Yes
10
11 Avira,Windows Defender
12 c:/wamp64
13 127.0.0.1 core
::1 core

I have a fresh install of wamp, set the mysql password, logged into phpmyadmin with that password.
Using 3-tier Presentation->Logic->Data layers.
In a webpage (Presentation) I require_once (Logic.php);
In Logic.php I require_once(Data.php).
In Data.php I have require_once(config.php);
public function __construct()
    {
        try 
        {
            $conn = new PDO("mysql:host={$host};name={$name}",$user,$pwd),array((PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION));
        }
        catch (PDOException $e) 
        {
            echo 'ERROR: ' . $e->get_message();
        }
    }

Config.php:
$user = 'root';
$pwd = 'password';
$dns = 'mysql:host=localhost;dbname=core';
try {
    $conn = new PDO($dns, $user, $pwd, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} 
catch (PDOException $e) 
{
    echo 'Error: ' . $e->getMessage();
}

At the bottom of Data.php I have $pdo = new PDO($dns,$user,$pwd);

Without the require_once, the website displays properly. Can't figure out if the problem is in mysql or php or both. Could it be a configuration issue? Happy to provide any other info.



Edited 1 time(s). Last edit at 11/19/2021 11:13AM by RiggsFolly.

Options: ReplyQuote
Re: Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
Posted by: Otomatic (Moderator)
Date: November 18, 2021 02:30PM

Hi,

This forum is not intended to correct the PHP scripts and SQL queries of Wampserver users.

However :

- 3 - Verify that all VC ++ packages are installed and with the latest versions.
To do this, use the tool:
Checks VC++ packages installed
Do not use a previously loaded tool. Make a new download to make sure you are using the correct version.[/u)
To download missing packages, do not rely on Microsoft links, they are not reliable, download packages on http://wampserver.aviatechno.net in section Visual C++ Redistribuable Packages
Do not forget that if you have a 64 bit Windows, you must install both 32 and 64 bit versions of each package.
You must install each package "as an administrator", so right-click the exe file and then run as Administrator.

- Apply Update 3.2.5 to your version of Wampserver
Wampserver update 3.2.5

> - 11 Avira,Windows Defender
It is not advisable to use two anti-viruses. Avira is too much, Windows Defender is enough.

> 13 127.0.0.1 core
> ::1 core
Localhost is missing

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote


Sorry, only registered users may post in this forum.