From 5736a23b8b1cc15500b42fd3d5cb5112e41d65c7 Mon Sep 17 00:00:00 2001 From: Wes Foster Date: Thu, 5 Dec 2013 16:41:49 -0600 Subject: [PATCH] Added array support to the where() function. --- MysqliDb.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/MysqliDb.php b/MysqliDb.php index 81acfce8..c7826450 100644 --- a/MysqliDb.php +++ b/MysqliDb.php @@ -227,15 +227,28 @@ public function delete($tableName, $numRows = null) * This method allows you to specify multipl (method chaining optional) WHERE statements for SQL queries. * * @uses $MySqliDb->where('id', 7)->where('title', 'MyTitle'); + * @uses $MySqliDb->where( array('id' => 7, 'title' => 'MyTitle') ); * - * @param string $whereProp The name of the database field. + * @param mixed $whereProp The name of the database field. Can also be an array of key/value pairs. * @param mixed $whereValue The value of the database field. * * @return MysqliDb */ - public function where($whereProp, $whereValue) + public function where($whereProp, $whereValue = null) { - $this->_where[$whereProp] = $whereValue; + // Process an array if given + if ( is_array( $whereProp ) AND is_null( $whereValue ) ) + { + foreach ( $whereProp as $key => $val ) { + $this->where($key, $val); + } + } + + // Otherwise, process single key/value arguments. + else { + $this->_where[$whereProp] = $whereValue; + } + return $this; }