queriesProfiling[$query])) $this->queriesProfiling[$query] = array('sum_time_ms' => 0, 'count' => 0); $time = $timer->getTimeMs(2); $time += $this->queriesProfiling[$query]['sum_time_ms']; $count = $this->queriesProfiling[$query]['count'] + 1; $this->queriesProfiling[$query] = array('sum_time_ms' => $time, 'count' => $count); } /** * When destroyed, if SQL profiled enabled, logs the SQL profiling information */ public function recordProfiling() { if(is_null($this->connection)) { return; } // turn off the profiler so we don't profile the following queries self::$profiling = false; foreach($this->queriesProfiling as $query => $info) { $time = $info['sum_time_ms']; $count = $info['count']; $queryProfiling = "INSERT INTO ".Piwik_Common::prefixTable('log_profiling')." (query,count,sum_time_ms) VALUES (?,$count,$time) ON DUPLICATE KEY UPDATE count=count+$count,sum_time_ms=sum_time_ms+$time"; $this->query($queryProfiling,array($query)); } // turn back on profiling self::$profiling = true; } /** * Connects to the DB * * @throws Exception if there was an error connecting the DB */ abstract public function connect(); /** * Disconnects from the server */ public function disconnect() { $this->connection = null; } /** * Returns an array containing all the rows of a query result, using optional bound parameters. * * @param string Query * @param array Parameters to bind * @see also query() * @throws Exception if an exception occured */ abstract public function fetchAll( $query, $parameters = array() ); /** * Returns the first row of a query result, using optional bound parameters. * * @param string Query * @param array Parameters to bind * @see also query() * * @throws Exception if an exception occured */ abstract public function fetch( $query, $parameters = array() ); /** * This function is a proxy to fetch(), used to maintain compatibility with Zend_Db interface * @see fetch() */ public function fetchRow( $query, $parameters = array() ) { return $this->fetch($query, $parameters); } /** * Return number of affected rows in last query * * @param mixed $queryResult Result from query() * @return int */ abstract public function rowCount($queryResult); /** * Executes a query, using optional bound parameters. * * @param string Query * @param array|string Parameters to bind array('idsite'=> 1) * * @return PDOStatement or false if failed * @throws Exception if an exception occured */ abstract public function query($query, $parameters = array()); /** * Returns the last inserted ID in the DB * Wrapper of PDO::lastInsertId() * * @return int */ abstract public function lastInsertId(); /** * Test error number * * @param Exception $e * @param string $errno * @return bool True if error number matches; false otherwise */ abstract public function isErrNo($e, $errno); }