According to the documentation, the Traversable
interface allows you to use the object into a foreach
loop and it's only supposed to be used internally. Think of it as a convenient way of using the PDOStatement.
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.
PDO::query()
and PDO::execute()
will not return the results on the other hand the PDOStatement object will allow you to specify the data you want to return. PDOStatement::fetchAll() will allow to define how you want to have your data organized.
It seems more complicated on first sight but it provides more flexibility.