Changeset 848 for trunk/system/libraries/Database.php
- Timestamp:
- 10/18/2007 10:36:47 PM (14 months ago)
- Files:
-
- 1 modified
-
trunk/system/libraries/Database.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/Database.php
r832 r848 41 41 // Database driver object 42 42 protected $driver; 43 protected $link; 43 44 44 45 // Un-compiled parts of the SQL query … … 56 57 protected $limit = FALSE; 57 58 protected $offset = FALSE; 58 protected $connected = FALSE;59 59 protected $last_query = ''; 60 60 … … 84 84 { 85 85 $name = $config; 86 86 87 87 // Test the config group name 88 88 if (($config = Config::item('database.'.$config)) === FALSE) … … 194 194 public function connect() 195 195 { 196 $this->connected = $this->driver->connect($this->config); 197 198 if ($this->connected != TRUE) 199 throw new Kohana_Exception('database.connection', $this->driver->show_error()); 196 if ( ! is_resource($this->link)) 197 { 198 if ( ! is_resource($this->link = $this->driver->connect($this->config))) 199 throw new Kohana_Exception('database.connection', $this->driver->show_error()); 200 } 200 201 } 201 202 … … 211 212 if ($sql == '') return FALSE; 212 213 213 if ( ! $this->connected) $this->connect(); 214 // No link? Connect! 215 $this->link or $this->connect(); 216 217 // Start the benchmark 218 $start = microtime(TRUE); 214 219 215 220 if (func_num_args() > 1) //if we have more than one argument ($sql) … … 218 223 $binds = (is_array(next($argv))) ? current($argv) : $argv; 219 224 } 225 220 226 // Compile binds if needed 221 227 if (isset($binds)) … … 223 229 $sql = $this->compile_binds($sql, $binds); 224 230 } 225 $this->last_query = $sql; 226 return $this->driver->query($sql); 231 232 // Fetch the result 233 $result = $this->driver->query($this->last_query = $sql); 234 235 // Stop the benchmark 236 $stop = microtime(TRUE); 237 238 if ($this->config['benchmark'] == TRUE) 239 { 240 // Benchmark the query 241 self::$benchmarks[] = array('query' => $sql, 'time' => $stop - $start); 242 } 243 244 return $result; 227 245 } 228 246 … … 540 558 $sql = $this->driver->compile_select(get_object_vars($this)); 541 559 542 $start = microtime(TRUE);543 560 $result = $this->query($sql); 544 $stop = microtime(TRUE);545 546 if ($this->config['benchmark'] == TRUE)547 {548 // Benchmark the query549 self::$benchmarks[] = array('query' => $sql, 'time' => $stop - $start);550 }551 561 552 562 $this->reset_select();
