[Solved] Fatal error: Uncaught Error: Call to a member function fetch() on boolean in #0 {main} thrown in on line 7 [duplicate]


Your PDO constructor is wrong. You are not declaring the database to which the PDO instance should connect to.

$db = new PDO('mysql:host=localhost;root', 'test', '');

The DSN should have the database name and the host name. You have root at the end of it which should not be there.

The line above should be like so:

$db = new PDO('mysql:host=localhost;dbname=dbnamehere', 'test', '');

Have a look at the documentation in the future and check that your code corresponds with it.

2

solved Fatal error: Uncaught Error: Call to a member function fetch() on boolean in #0 {main} thrown in on line 7 [duplicate]