I have been using this same exact code and now with this new project, I can't get it to connect to my database. It is running on the same server and everything as the older ones.
In fact, I even copied and pasted this info into my new project from an old project, replaced the password and username fields to match this project, and It did not work.
The code is:
<?php
$host = 'localhost';
$dbname = '';
$user = '';
$pass = '';
$db = new PDO('mysql:host='.$host.';dbname='.$dbname.'', $user, $pass);
?>
I get this error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory'
What difference would it be making? I don't understand. it's in the same root as the other projects just in a diff. folder.
--root
-- project 1
-- project 2