I have started using PDO in php for the first time.
Here is my code:
$host="localhost";
$dbname="meme";
$user="root";
$pass="dream";
global $dbh;
try
{
//dbh : Database Handle
$dbh= new PDO("mysql:host=$host;dbname=$dbname,$user,$pass");
}
catch(PDOException $e)
{
echo $e->getMessage();
}
I got this error:
SQLSTATE[28000] [1045] Access denied for user 'www-data'@'localhost'
(using password: NO)
I guess its a common error as I could get a number of related posts on both Google and StackOverflow but I fail to correct it maybe because of my limited knowledge in the field. Any help is appreciated.
Use this instead:
You have quoted the DSN, username, and password altogether. This way those 3 parameters are actually only one parameter. Therefore from PDO’ constructors POV, you are not passing username, and password.