PDO::query()
returns false
(which obviously is a non-object) if the query fails. So that's your problem. Your query has an error.
I recommend you to set the error mode in PDO.
$db->setAttribute(PDO::ATTR_ERRMODE, PDO:ERRMODE_EXCEPTION);
and then catch the error to see what is wrong with your query.
The different error modes that exist is PDO::ERRMODE_SILENT
, PDO::ERRMODE_WARNING
and PDO:ERRMODE_EXCEPTION
. You can read about them in the PHP manual on PDO. Knowing how to debug when writing SQL is important and the key to not having to ask these kind of questions.
About your other problem
You gotta select the id column if you want to use it.
SELECT * FROM articles
or
SELECT id, title FROM articles