Whenever you fetch records with eg. Doctrine_Table::findAll or Doctrine_Connection::query methods an instance of Doctrine_Collection is returned. There are many types of collections in Doctrine and it is crucial to understand the differences of these collections. Remember choosing the right fetching strategy (collection type) is one of the most influental things when it comes to boosting application performance.

  • Immediate Collection
  • Batch Collection
  • Lazy Collection
  • Offset Collection $table = $conn->getTable("User"); $table->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_IMMEDIATE); $users = $table->findAll(); // or $users = $conn->query("FROM User-I"); // immediate collection foreach($users as $user) { print $user->name; } $table->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_LAZY); $users = $table->findAll(); // or $users = $conn->query("FROM User-L"); // lazy collection foreach($users as $user) { print $user->name; } $table->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_BATCH); $users = $table->findAll(); // or $users = $conn->query("FROM User-B"); // batch collection foreach($users as $user) { print $user->name; } $table->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_OFFSET); $users = $table->findAll(); // or $users = $conn->query("FROM User-O"); // offset collection foreach($users as $user) { print $user->name; }