/** * 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); }
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(); } }
echo $key; ?> "><?php echo ucfirst($key); ?> </th> <?php } ?> </tr> <?php foreach ($benchmarks as $name => $tokens) { ?> <tr class="mark time"> <?php $stats = Profiler::stats($tokens); ?> <th class="name" rowspan="2" scope="rowgroup"><?php echo $name, ' (', count($tokens), ')'; ?> </th> <?php foreach ($group_cols as $key) { ?> <td class="<?php echo $key; ?> "> <div> <div class="value"><?php echo number_format($stats[$key]['time'], 6);
/** * 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(); }
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); } }
/** * Execute the current query on the given database. * * @param mixed $db Database instance or name of instance * @param string result object classname, TRUE for stdClass or FALSE for array * @param array result object constructor arguments * @return object Database_Result for SELECT queries * @return mixed the insert id for INSERT queries * @return integer number of affected rows for all other queries */ public function execute($db = NULL, $as_object = NULL, $object_params = NULL) { if (!is_object($db)) { // Get the database instance $db = Database::instance($db); } if ($as_object === NULL) { $as_object = $this->_as_object; } if ($object_params === NULL) { $object_params = $this->_object_params; } // Compile the SQL query $sql = $this->compile($db); if ($this->_lifetime !== NULL and $this->_type === Database::SELECT) { // Set the cache key based on the database instance name and SQL $cache_key = 'Database::query("' . $db . '", "' . $sql . '")'; // Read the cache first to delete a possible hit with lifetime <= 0 if (($result = Profiler::cache($cache_key, NULL, $this->_lifetime)) !== NULL and !$this->_force_execute) { // Return a cached result return new Database_Result_Cached($result, $sql, $as_object, $object_params); } } // Execute the query $result = $db->query($this->_type, $sql, $as_object, $object_params); if (isset($cache_key) and $this->_lifetime > 0) { // Cache the result array Profiler::cache($cache_key, $result->as_array(), $this->_lifetime); } return $result; }
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; } }