Beispiel #1
0
function dbal_delete($table, $clauses=array()) {
    $table = dbal_table($table);
    $query = "DELETE FROM `$table` WHERE 1";
    foreach ($clauses as $clause) {
        $comparison = '=';
        if (sizeof($clause) == 3) {
            if (array_search($clause[2], array('=', '<=', '>=', '<', '>'))) {
                $comparison = $clause[2];
            }
        } else if (sizeof($clause) != 2) {
            throw new Exception("Invalid argument: Clauses must be 2 or 3 tuples of key, value[, comparison]");
        }
        $key = $clause[0];
        $value = $clause[1];
        $query .= ' AND `' . mysql_real_escape_string($key) . "`$comparison'" . mysql_real_escape_string($value) . "'";
    }
    return mysql_query($query);
}
Beispiel #2
0
<?php
require_once dirname(__FILE__) . '/../dbal.php';
$table = dbal_table('stats');
$sql = "SELECT name, ROUND(microtime/1000) sec, COUNT(*) cnt FROM `$table` GROUP BY name, sec ORDER BY name, sec ASC";
$rows = dbal_query_sql($sql, true);
$charts = array();
foreach ($rows as $row) {
    if (!array_key_exists($row['name'], $charts)) {
        $charts[$row['name']] = array();
    }
    $charts[$row['name']][] = array('hit' => $row['cnt'], 'sec' => $row['sec']);
}
$sql = "SELECT name, STDDEV(microtime/1000) dev, AVG(microtime/1000) avg FROM `$table` GROUP BY name ORDER BY name";
$rows = dbal_query_sql($sql, true);
$stddev = array();
foreach ($rows as $row) {
    $dev = floatval($row['dev']);
    $avg = floatval($row['avg']);
    $stddev[$row['name']] = array("avg" => $avg, "min" => $avg-$dev, "max" => $avg+$dev);
}
?>
<html>
    <head><title>Statistics of IceRSS</title>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
function drawChart() { <? $i = 1;foreach ($charts as $name => $chart) { ?>
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'seconds');
    data.addColumn('number', 'hits');