示例#1
0
 /**
  * Get a database connection by name r return the default
  *
  * @param string
  * @return object
  */
 public static function connection($name = null)
 {
     // use the default connection if none is specified
     if (is_null($name)) {
         $name = Config::db('default');
     }
     // if we have already connected just return the instance
     if (isset(static::$connections[$name])) {
         return static::$connections[$name];
     }
     // connect and return
     return static::$connections[$name] = static::factory(Config::db('connections.' . $name));
 }
示例#2
0
 /**
  * A simple database query wrapper
  *
  * @param string
  * @param array
  * @return array
  */
 public function ask($sql, $binds = array())
 {
     try {
         if (Config::db('profiling')) {
             $this->queries[] = compact('sql', 'binds');
         }
         $statement = $this->instance()->prepare($sql);
         $result = $statement->execute($binds);
         return array($result, $statement);
     } catch (Exception $e) {
         $error = 'Database Error: ' . $e->getMessage() . '</code></p><p><code>SQL: ' . trim($sql);
         throw new Exception($error, 0, $e);
     }
 }