tags:

views:

37

answers:

2

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?

+1  A: 

It's because statements can be executed, and when they are, the resulting rows are stored inside of a buffer. In essence, the object contains not only the records it returned, but information on how to execute it again. That's why it's called a statement.

amphetamachine
+2  A: 

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

Pascal MARTIN