Php – n conceptual difference between a so called “record set” and an so called “statement”

databasePHPsql

I wonder why the result of an SQL query in PHP PDO is called "statement". I'd expect "record set". My english is pretty bad as I'm not a native speaker.

So: I craeate a "query" to "ask the database to do/retrieve something". Sometimes I use "prepared statements" to ask that (blue confusion alert!). Then, PDO returns me an object of class called PDOStatement (red confusion alert!). Then, this PDOStatement object has a fetch() method, which seems to return me a "record set". All right…so is there any logical difference between that PDOStatement thing and the record set I get from fetch()?

What's the difference? Or does the PDOStatement object actually perform the DB query and then return a record set? Or is PDOStatement the record set?

Best Answer

The PDOStatement represents both statements and result sets ; quoting the manual :

Represents a prepared statement and, after the statement is executed, an associated result set.

And the PDO::query method :

Executes an SQL statement, returning a result set as a PDOStatement object