Example #1
0
 /**
  *  Get widget
  *  @param  [string] $name  [Name of template file]
  *  @param  [array]  $array [Array with data -> go to template]
  *  @return [string]        [Widget HTML]
  */
 public static function get($name, $array = array())
 {
     $token = Profiler::start('Profiler', 'Widget ' . $name);
     $w = Widgets::factory();
     if (isset($w->_data[$name])) {
         return $w->_data[$name];
     }
     if (method_exists($w, $name)) {
         return $w->{$name}($array);
     }
     Profiler::stop($token);
     return $w->common($name, $array);
 }
Example #2
0
 public function query($type, $sql, $as_object = FALSE, array $params = NULL)
 {
     // Make sure the database is connected
     $this->_connection or $this->connect();
     if (PROFILER) {
         // Benchmark this query for the current instance
         $benchmark = Profiler::start("Database ({$this->_instance})", $sql);
     }
     try {
         $result = $this->_connection->query($sql);
     } catch (Exception $e) {
         if (isset($benchmark)) {
             // This benchmark is worthless
             Profiler::delete($benchmark);
         }
         // Convert the exception in a database exception
         die($e->getMessage() . ' [ ' . $sql . ' ]');
     }
     if (isset($benchmark)) {
         Profiler::stop($benchmark);
     }
     // Set the last query
     $this->last_query = $sql;
     if ($type === Database::SELECT) {
         // Convert the result into an array, as PDOStatement::rowCount is not reliable
         if ($as_object === FALSE) {
             $result->setFetchMode(PDO::FETCH_ASSOC);
         } elseif (is_string($as_object)) {
             $result->setFetchMode(PDO::FETCH_CLASS, $as_object, $params);
         } else {
             $result->setFetchMode(PDO::FETCH_CLASS, 'stdClass');
         }
         $result = $result->fetchAll();
         // Return an iterator of results
         return new Database_Result_Cached($result, $sql, $as_object, $params);
     } elseif ($type === Database::INSERT) {
         // Return a list of insert id and rows created
         return array($this->_connection->lastInsertId(), $result->rowCount());
     } else {
         // Return the number of rows affected
         return $result->rowCount();
     }
 }
Example #3
0
 public function query($type, $sql, $as_object = FALSE, array $params = NULL)
 {
     // Make sure the database is connected
     $this->_connection or $this->connect();
     if (PROFILER) {
         // Benchmark this query for the current instance
         $benchmark = Profiler::start("Database ({$this->_instance})", $sql);
     }
     if (!empty($this->_config['connection']['persistent']) and $this->_config['connection']['database'] !== Database_MySQL::$_current_databases[$this->_connection_id]) {
         // Select database on persistent connections
         $this->_select_db($this->_config['connection']['database']);
     }
     // Execute the query
     if (($result = mysql_query($sql, $this->_connection)) === FALSE) {
         if (isset($benchmark)) {
             // This benchmark is worthless
             Profiler::delete($benchmark);
         }
         die(mysql_error($this->_connection) . '. Query: ' . $sql . '. Code: ' . mysql_errno($this->_connection));
     }
     if (isset($benchmark)) {
         Profiler::stop($benchmark);
     }
     // Set the last query
     $this->last_query = $sql;
     if ($type === Database::SELECT) {
         // Return an iterator of results
         return new Database_MySQL_Result($result, $sql, $as_object, $params);
     } elseif ($type === Database::INSERT) {
         // Return a list of insert id and rows created
         return array(mysql_insert_id($this->_connection), mysql_affected_rows($this->_connection));
     } else {
         // Return the number of rows affected
         return mysql_affected_rows($this->_connection);
     }
 }
Example #4
0
 /**
  *  Run controller->action
  */
 protected function start($path, $action)
 {
     $action .= 'Action';
     $controller = implode('\\', $path);
     $controller = new $controller();
     $controller->before();
     $token = Profiler::start('Profiler', 'Center');
     $controller->{$action}();
     Profiler::stop($token);
     $controller->after();
 }
Example #5
0
 public function query($type, $sql, $as_object = FALSE, array $params = NULL)
 {
     // Make sure the database is connected
     $this->_connection or $this->connect();
     if (PROFILER) {
         // Benchmark this query for the current instance
         $benchmark = Profiler::start("Database ({$this->_instance})", $sql);
     }
     // Execute the query
     if (($result = $this->_connection->query($sql)) === FALSE) {
         if (isset($benchmark)) {
             // This benchmark is worthless
             Profiler::delete($benchmark);
         }
         die($this->_connection->error . ' [ ' . $sql . ' ]');
     }
     if (isset($benchmark)) {
         Profiler::stop($benchmark);
     }
     // Set the last query
     $this->last_query = $sql;
     if ($type === Database::SELECT) {
         // Return an iterator of results
         return new Database_MySQLi_Result($result, $sql, $as_object, $params);
     } elseif ($type === Database::INSERT) {
         // Return a list of insert id and rows created
         return array($this->_connection->insert_id, $this->_connection->affected_rows);
     } else {
         // Return the number of rows affected
         return $this->_connection->affected_rows;
     }
 }