Changeset 2058

Show
Ignore:
Timestamp:
02/15/2008 10:17:27 AM (11 months ago)
Author:
zombor
Message:

Adding IN support, fixing #336. Thanks allain.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Database.php

    r2034 r2058  
    789789 
    790790        /** 
     791         * Adds an "in" condition to the where clause 
     792         *  
     793         * @param   string  Name of the column being examined 
     794         * @param   mixed   An array or string to match against 
     795         * @return  object  This Database object. 
     796         */ 
     797        public function in($field, $values)  
     798        { 
     799                if (is_array($values)) 
     800                { 
     801                        $escaped_values = array(); 
     802                        foreach ($values as $v) 
     803                        { 
     804                                if (is_numeric($v))  
     805                                { 
     806                                        $escaped_values[] = $v; 
     807                                } 
     808                                else 
     809                                { 
     810                                        $escaped_values[] = "'".$this->driver->escape_string($v)."'"; 
     811                                } 
     812                        } 
     813                        $values = implode(",", $escaped_values); 
     814                } 
     815                $this->where($this->driver->escape_column($field).' IN('.$values.')'); 
     816                 
     817                return $this; 
     818        } 
     819 
     820        /** 
    791821         * Compiles a merge string and runs the query. 
    792822         *