diff options
author | Jamie Matthews <[email protected]> | 2010-10-07 01:03:55 +0100 |
---|---|---|
committer | Jamie Matthews <[email protected]> | 2010-10-07 01:03:55 +0100 |
commit | b9651bb00250452aa10a6b695cda627695a7bf05 (patch) | |
tree | 1e60068bd49a7bfadb9d8dc912e5dd4447bff9f7 /idiorm.php | |
parent | 0e40a2014a589245005d63516cd6f2e45e392785 (diff) |
Add where_in and where_not_in methods, tests and docs
Diffstat (limited to 'idiorm.php')
-rw-r--r-- | idiorm.php | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -334,6 +334,14 @@ } /** + * Return a string containing the given number of question marks, + * separated by commas. Eg "?, ?, ?" + */ + protected function _create_placeholders($number_of_placeholders) { + return join(", ", array_fill(0, $number_of_placeholders, "?")); + } + + /** * Add a WHERE column = value clause to your query. Each time * this is called in the chain, an additional WHERE will be * added, and these will be ANDed together when the final query @@ -394,6 +402,24 @@ } /** + * Add a WHERE ... IN clause to your query + */ + public function where_in($column_name, $values) { + $column_name = $this->_quote_identifier($column_name); + $placeholders = $this->_create_placeholders(count($values)); + return $this->_add_where("{$column_name} IN ({$placeholders})", $values); + } + + /** + * Add a WHERE ... NOT IN clause to your query + */ + public function where_not_in($column_name, $values) { + $column_name = $this->_quote_identifier($column_name); + $placeholders = $this->_create_placeholders(count($values)); + return $this->_add_where("{$column_name} NOT IN ({$placeholders})", $values); + } + + /** * Add a raw WHERE clause to the query. The clause should * contain question mark placeholders, which will be bound * to the parameters supplied in the second argument. |