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.
我想知道为什么PHP PDO中的SQL查询的结果被称为“语句”。我希望“纪录”。我的英语很糟糕,因为我的母语不是英语。
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()?
所以:我想要一个“查询”来“让数据库去做/检索一些东西”。有时我会用“准备好的陈述”来问这个问题(蓝色的混乱警报!)然后,PDO返回一个名为PDOStatement的类对象(红色混乱警报!)然后,这个PDOStatement对象有一个fetch()方法,它似乎返回给我一个“记录集”。好吧……那么PDOStatement和我从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?
有什么区别呢?还是PDOStatement对象实际执行DB查询,然后返回一个记录集?或者PDOStatement是被设置的记录?
2 个解决方案
#1
2
The PDOStatement
represents both statements and result sets ; quoting the manual :
PDOStatement同时表示语句和结果集;引用手册:
Represents a prepared statement and, after the statement is executed, an associated result set.
表示一个准备好的语句,在执行语句之后,将生成一个关联的结果集。
And the PDO::query
method :
和PDO::查询方法:
Executes an SQL statement, returning a result set as a
PDOStatement
object执行一条SQL语句,返回一个作为PDOStatement对象的结果集
#2
1
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.
这是因为语句可以执行,当它们执行时,结果行存储在缓冲区中。本质上,对象不仅包含它返回的记录,还包含关于如何再次执行它的信息。这就是为什么它被称为语句。
#1
2
The PDOStatement
represents both statements and result sets ; quoting the manual :
PDOStatement同时表示语句和结果集;引用手册:
Represents a prepared statement and, after the statement is executed, an associated result set.
表示一个准备好的语句,在执行语句之后,将生成一个关联的结果集。
And the PDO::query
method :
和PDO::查询方法:
Executes an SQL statement, returning a result set as a
PDOStatement
object执行一条SQL语句,返回一个作为PDOStatement对象的结果集
#2
1
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.
这是因为语句可以执行,当它们执行时,结果行存储在缓冲区中。本质上,对象不仅包含它返回的记录,还包含关于如何再次执行它的信息。这就是为什么它被称为语句。