summaryrefslogtreecommitdiff
path: root/idiorm.php
diff options
context:
space:
mode:
authorJamie Matthews <[email protected]>2010-10-07 01:03:55 +0100
committerJamie Matthews <[email protected]>2010-10-07 01:03:55 +0100
commitb9651bb00250452aa10a6b695cda627695a7bf05 (patch)
tree1e60068bd49a7bfadb9d8dc912e5dd4447bff9f7 /idiorm.php
parent0e40a2014a589245005d63516cd6f2e45e392785 (diff)
Add where_in and where_not_in methods, tests and docs
Diffstat (limited to 'idiorm.php')
-rw-r--r--idiorm.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/idiorm.php b/idiorm.php
index d2c26da..2d5bf8e 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -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.