I'm a php and mysql beginner, I'm currently self study PDO and confused some concepts:
1.What is the relationship between PDO class and PDOStatement class?
2.Someone said $users is the cursor, once consumed, it won't rewind to the beginning of the resultset.
but why you can use it in a 3.For the pdostatement class, the doc said:
why this class implements Traversable interface? is it empty interface? Thank you for help!
|
|||||||||||||||||
|
According to the documentation, the Basically, with PDO there is two ways to execute a query, one by using PDO::prepare() & PDOStatement::execute() and the other one by using PDO::query(). The later does prepare/execute in one call.
It seems more complicated on first sight but it provides more flexibility. |
|||
All that mess is called "syntax sugar" and intended to sweeten a developer's life, though in real it makes taste too sugary to the point of disgust. So, there are two kinds of object's characteristics - natural and unnatural ones. In your place I'd just forget of them, using objects straight way.
That's 2 different classes. They serve different purposes. Like in old mysql you had connection resource and result resource. You have only one connection/PDO instance, but there can be any number actual query results/stmt classes.
That's the very syntax sugar I talked above. They just added such a possibility to the statement object. |