Beispiel #1
0
 /**
  * Returns a select query for the given persistent object $class.
  *
  * The query is initialized to fetch all columns from the correct table and
  * has correct alias mappings between columns and property names of the
  * persistent $class. The alias mapping allows you to use property names in
  * WHERE conditions, instead of column names. These aliases will
  * automatically be resolved before querying the database.
  *
  * Example:
  * <code>
  * <?php
  *
  * $q = $session->createFindQuery( 'Person' );
  * $allPersons = $session->find( $q, 'Person' );
  *
  * ?>
  * </code>
  *
  * Example with aliases:
  * <code>
  * <?php
  * $q = $session->createFindQuery( 'Person' );
  * $q->where(
  *     $q->expr->eq(
  *         'zipCode',
  *         $q->bindValue( 12345 )
  *     )
  * );
  * $somePersons = $session->find( $q, 'Person' );
  * 
  * ?>
  * </code>
  * $zipCode is the property name in the Person class, while the
  * corresponding database column is named zip_code.
  *
  * @throws ezcPersistentObjectException
  *         if there is no such persistent class.
  *
  * @param string $class
  *
  * @return ezcPersistentFindQuery
  */
 public function createFindQuery($class)
 {
     return $this->session->createFindQuery($class);
 }
<?php

require 'ezc-setup.php';
$session = new ezcPersistentSession(ezcDbInstance::get(), new ezcPersistentCodeManager("path/to/definitions"));
// Creating New Objects
$object = new City();
$object->normalized_name = "dieren";
$object->name = 'Dieren';
$object->country = 'NL';
$session->save($object);
// Finding Objects
$q = $session->createFindQuery('City');
$q->where($sq->expr->like('name', $sq->bindValue('oslo%')))->orderBy('country', 'name')->limit(10);
$objects = $session->findIterator($q, 'City');
foreach ($objects as $object) {
}