Working with objects - Component overview - Record - Retrieving existing records.php 690 Bytes
Newer Older
hansbrix's avatar
hansbrix committed
1 2 3
Doctrine provides many ways for record retrieval. The fastest ways for retrieving existing records
are the finder methods provided by Doctrine_Table. If you need to use more complex queries take a look at
DQL API and Doctrine_Connection::query method.
4

hansbrix's avatar
hansbrix committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<code type="php">
$table = $conn->getTable("User");

// find by primary key

$user = $table->find(2);
if($user !== false)
    print $user->name;

// get all users
foreach($table->findAll() as $user) {
    print $user->name;
}

// finding by dql
foreach($table->findByDql("name LIKE '%John%'") as $user) {
    print $user->created;
}

// finding objects with DQL

$users = $conn->query("FROM User WHERE User.name LIKE '%John%'");
</code>