XHProfRuns_Default::getRuns PHP Méthode

getRuns() public méthode

This function gets runs based on passed parameters, column data as key, value as the value. Values are escaped automatically. You may also pass limit, order by, group by, or "where" to add those values, all of which are used as is, no escaping.
public getRuns ( array $stats ) : resource
$stats array Criteria by which to select columns
Résultat resource
    public function getRuns($stats)
    {
        if (isset($stats['select'])) {
            $query = "SELECT {$stats['select']} FROM `details` ";
        } else {
            $query = "SELECT * FROM `details` ";
        }
        $skippers = array("limit", "order by", "group by", "where", "select");
        $hasWhere = false;
        foreach ($stats as $column => $value) {
            if (in_array($column, $skippers)) {
                continue;
            }
            if ($hasWhere === false) {
                $query .= " WHERE ";
                $hasWhere = true;
            } elseif ($hasWhere === true) {
                $query .= "AND ";
            }
            if (strlen($value) == 0) {
                $query .= $column;
            }
            $value = $this->db->escape($value);
            $query .= " `{$column}` = '{$value}' ";
        }
        if (isset($stats['where'])) {
            if ($hasWhere === false) {
                $query .= " WHERE ";
                $hasWhere = true;
            } else {
                $query .= " AND ";
            }
            $query .= $stats['where'];
        }
        if (isset($stats['group by'])) {
            $query .= " GROUP BY `{$stats['group by']}` ";
        }
        if (isset($stats['order by'])) {
            $query .= " ORDER BY `{$stats['order by']}` DESC";
        }
        if (isset($stats['limit'])) {
            $query .= " LIMIT {$stats['limit']} ";
        }
        $resultSet = $this->db->query($query);
        return $resultSet;
    }

Usage Example

Exemple #1
0
    // ridiculously long.
    if ($params[$k] == $v[1]) {
        unset($params[$k]);
    }
}
$vbar = ' class="vbar"';
$vwbar = ' class="vwbar"';
$vwlbar = ' class="vwlbar"';
$vbbar = ' class="vbbar"';
$vrbar = ' class="vrbar"';
$vgbar = ' class="vgbar"';
$xhprof_runs_impl = new XHProfRuns_Default();
if (isset($_GET['geturl'])) {
    $rs = $xhprof_runs_impl->getUrlStats(array("url" => $_GET['geturl'], 'limit' => 100));
    showChart($rs);
    $rs = $xhprof_runs_impl->getRuns(array('url' => $_GET['geturl'], 'limit' => 100));
    $url = htmlentities($_GET['geturl'], ENT_QUOTES);
    displayRuns($rs, "Runs with URL: {$url}");
} elseif (isset($_GET['getcurl'])) {
    $rs = $xhprof_runs_impl->getUrlStats(array("c_url" => $_GET['getcurl'], 'limit' => 100));
    showChart($rs);
    $url = htmlentities($_GET['getcurl'], ENT_QUOTES);
    $rs = $xhprof_runs_impl->getRuns(array('c_url' => $_GET['getcurl'], 'limit' => 100));
    displayRuns($rs, "Runs with Simplified URL: {$url}");
} elseif (isset($_GET['last'])) {
    $last = (int) $_GET['last'];
    $rs = $xhprof_runs_impl->getRuns(array("order by" => 'timestamp', 'limit' => $last));
    displayRuns($rs, "Last {$last} Runs");
} elseif (isset($_GET['getruns'])) {
    $days = (int) $_GET['days'];
    switch ($_GET['getruns']) {