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.

<?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();
}

?>

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);

Thanks, that got it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.