Changeset 664
- Timestamp:
- 10/05/2007 10:33:08 AM (14 months ago)
- Files:
-
- 1 modified
-
trunk/system/libraries/Database.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/Database.php
r658 r664 147 147 * @access public 148 148 * @param string 149 * @param array 149 150 * @param boolean 150 151 * @return mixed 151 152 */ 152 public function query($sql = '', $ object = FALSE)153 public function query($sql = '', $binds = FALSE, $object = FALSE) 153 154 { 154 155 if ($sql == '') return FALSE; … … 157 158 $object = (bool) ($object == FALSE) ? $this->config['object'] : $object; 158 159 160 // Compile binds if needed 161 if ($binds !== FALSE) 162 { 163 $sql = $this->compile_binds($sql, $binds); 164 } 165 159 166 $this->last_query = $sql; 160 167 return $this->driver->query($sql, $object); … … 724 731 } 725 732 726 733 /** 734 * Compile Bindings 735 * 736 * @access public 737 * @param string the sql statement 738 * @param array an array of bind data 739 * @return string 740 */ 741 public function compile_binds($sql, $binds) 742 { 743 if (strpos($sql, '?') === FALSE) 744 { 745 return $sql; 746 } 747 748 $binds = (array) $binds; 749 750 foreach ($binds as $val) 751 { 752 $val = $this->driver->escape($val); 753 754 // Just in case the replacement string contains the bind 755 // character we'll temporarily replace it with a marker 756 $val = str_replace('?', '{%bind_marker%}', $val); 757 $sql = preg_replace("#".preg_quote('?', '#')."#", str_replace('$', '\$', $val), $sql, 1); 758 } 759 760 return str_replace('{%bind_marker%}', '?', $sql); 761 } 727 762 } // End Database Class
