Created
March 1, 2012 19:55
-
-
Save Naouak/1952656 to your computer and use it in GitHub Desktop.
WHERE with "AND" AND "OR"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add a single condition, or an array of conditions to the WHERE clause of the query. | |
* | |
* Usage: | |
* $query->where('a = 1')->where('b = 2'); | |
* $query->where(array('a = 1', 'b = 2')); | |
* | |
* @param mixed $conditions A string or array of where conditions. | |
* @param string $glue The glue by which to join the conditions. Defaults to AND. | |
* Note that the glue is set on first use and cannot be changed. | |
* | |
* @return JDatabaseQuery Returns this object to allow chaining. | |
* | |
* @since 11.1 | |
*/ | |
public function where($conditions, $glue = 'AND') | |
{ | |
if (is_null($this->where)) | |
{ | |
$glue = strtoupper($glue); | |
$this->where = new JDatabaseQueryElement('WHERE', $conditions, " $glue "); | |
} | |
else | |
{ | |
$this->where->append($conditions); | |
} | |
return $this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment