I've got the following code:
try { $db = new PDO('mysql:host=127.0.0.1;db=example', 'root', ''); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $db->query('SELECT * FROM posts'); } catch (PDOException $e) { echo $db->errorCode(); var_dump($db->errorInfo()); } And I get the following error:
3D000array(3) { [0]=> string(5) "3D000" [1]=> int(1046) [2]=> string(20) "No database selected" } However, this ONLY occurs when I include $stmt = $db->query('SELECT * FROM posts');
This is my first time with PDO, Would anyone know why this is not working? The database and table exist.
exampleexist? You should write database name atexample