previous->selectAdd() (Previous) (Next) ->escape()next

View this page in Last updated: Tue, 02 Jun 2009
English | Brazilian Portuguese | Chinese | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Turkish

->whereAdd()

->whereAdd() – Add WHERE statement

Synopsis

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

Description

Adds items to the where part of a SQL query. Calling this without any arguments clears the where condition. The default behavior is to add 'AND' to the existing conditions, use the $logic parameter to append OR conditions.

Parameter

  • string $cond - condition to add, or blank to reset the conditions

  • string $logic - optional logic "OR" (defaults to "AND")

Note

This function can not be called statically.

The quote_identifiers configuration option will not affect data sent to whereAdd.

See

Example

Using 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 />";
}
?>

Resulting SQL


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

SELECT * FROM person WHERE age < 12 OR age > 30
previous->selectAdd() (Previous) (Next) ->escape()next

Download Documentation Last updated: Tue, 02 Jun 2009
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
There are no user contributed notes for this page.