Try:
$pdo = new \PDO($dsn);
And put password as ''.
Im doing the php beginners course for a refresher after a 20 year hiatus from php and I'm having issues with the PDO / mysql lesson.
This is the lesson -> https://laracasts.com/series/php-for-beginners-2023-edition/episodes/17?page=1
My code looks like this
$dsn = "mysql:host=localhost;port:3306;dbname=aur;user=root;charset=utf8mb4";
$pdo = new PDO($dsn);
$statement = $pdo->prepare("select * from posts");
$statement->execute();
$posts = $statement->fetchAll();
dd($posts);
The error I'm getting is the following (database does not exist)
Fatal error: Uncaught PDOException: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected
Please help.
I'm not sure why the code from the video wont work for me.
I just referred to the php documentation and typed the code out again using the following and it worked.
$dsn = 'mysql:dbname=aur;host=127.0.0.1';
$user = 'root';
$pdo = new PDO($dsn, $user);
Thanks anyway!
Please or to participate in this conversation.