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
11 Avira,Windows Defender
12 c:/wamp64
13 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()
            $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();

$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


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 core
> ::1 core
Localhost is missing

Wampserver 3.2.9 32 bit - Apache 2.4.54 - PHP 8.1.8…5.6.40 - MySQL 5.7.39 - MariaDB 10.5.13/10.6.5
Wampserver 3.2.9 64 bit - Apache 2.4.54 - PHP 8.1.8…5.6.40 - MySQL 5.7.39/8.0.30 - MariaDB 10.5.15/10.7.3
PhPMyadmin 5.1.3 - MysqlDumper 1.24.5
on W10 and W7 Pro 64 bit
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons
« Ce n'est pas parce qu'ils sont nombreux à avoir tort, qu'ils ont forcément raison. Coluche »
« It's not because they are many to be wrong, they are necessarily right. Coluche »

Options: ReplyQuote

Sorry, only registered users may post in this forum.