0

I get the following in my web browser when I try to connect to my mariaDB database.
Error!: SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)
It also doesn't matter if I use mariaDB root or a regular users credentials, I get the same thing.
The error above that's showing up in my web browser is the same error I get if I leave the -p option off when logging into mysql through the command line.
mysql -u root -> Error!: SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)
mysql -u root -p all good

Any ideas? Thanks.

2
Contributors
3
Replies
12
Views
1 Year
Discussion Span
Last Post by lewashby
0
<?php

include('./constants.php');

try
{
    $connection = new PDO("mysql:host=$host; dbname=$db_name, $db_user, $password");
}

catch (PDOException $e)
{
    print "Error!: " . $e->getMessage() . "<br />";
    die();
}

?>
1

Hi,

you are submitting a single string to the PDO constructor:

$connection = new PDO("mysql:host=$host; dbname=$db_name, $db_user, $password");

instead they should be three: dsn, username, password. Or four if appending options:

$connection = new PDO("mysql:host=$host;dbname=$db_name", $db_user, $password);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.