->whereAdd()

->whereAdd() – Ajoute une instruction WHERE

Synopsis

void $DB_DataObject->whereAdd ( string $where , string $logic )

Description

Ajoute des éléments à la partie de l'instruction WHERE d'une requête SQL. L'appel à cette méthode sans aucun argument efface l'instruction WHERE. Le comportement ar défaut est d'ajouter 'AND' aux conditions existantes, utilisez le paramètre $logic pour ajouter des conditions 'OR'.

Parameter

  • string $cond - condition à ajouter, ou vide pour effacer les conditions existantes

  • string $logic - logique, optionnel "OR" (par défaut, vaut "AND")

Note

This function can not be called statically.

See

Example

Exemple avec whereAdd()

<?php
$person 
= new DataObjects_Person;
$person->whereAdd('age > 12');
$person->whereAdd('age < 30');
$person->find();

while (
$person->fetch()) {
   echo 
"$person->id{$person->name}<br />";
}
$person = new DataObjects_Person;
$person->whereAdd('age < 12');
$person->whereAdd('age > 30''OR');
$person->find();

while (
$person->fetch()) {
   echo 
"{$person->id} {$person->name}<br />";
}
?>

SQL résultant


SELECT * FROM person WHERE age > 12 AND age < 30
SELECT * FROM person WHERE age < 12 OR age > 30