- Edited
otuatail I was told on another forum that ALL sql had to be prepared
SQL
Prepare
Execute
If you aren't using any placeholders to supply variables to the query, then pdo_query
does both the preparation and execution steps immediately. If there aren't any placeholders in the SQL statement then there's nothing to do between preparation and execution so they don't need to be split into two steps. This is why the manual page for pdo_query says that the method "prepares and executes an SQL statement without placeholders".
otuatail I am using a server with PHP5.4 is that the reason? PDO does not work on this version.
No, PDO has been around since 5.1.
Yes, because you're telling your PDO connection to return results as objects instead of arrays. That is what the
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
setting you've used does.
See PDO constants for a list of the other FETCH_*
options available. Some of them make PDO give you arrays, some give you objects.