开发者

Is there an conceptual difference between a so called "record set" and an so called "statement"?

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开发者_Python百科: 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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜