示例#1
0
function bmark_query($sql, $dbh)
{
    $result_set = null;
    if (is_a($dbh, "DrizzleCon")) {
        $sql = str_replace("ENGINE=InnoDB DEFAULT CHARSET=utf8", "", $sql);
        $result = @drizzle_query($dbh, $sql) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
        // buffer result set
        drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
        if (drizzle_result_row_count($result)) {
            while ($row = drizzle_row_next($result)) {
                $result_set[] = $row;
            }
        }
        // free result set
        drizzle_result_free($result);
        // close connection
        // drizzle_con_close($dbh);
        return $result_set;
    }
    if (bmark_type($dbh) === 'mysql') {
        $result = mysql_query($sql, $dbh) or die('ERROR: ' . mysql_error($dbh));
        if (preg_match("/select.*/i", $sql)) {
            if (mysql_num_rows($result) > 0) {
                while ($row = mysql_fetch_assoc($result)) {
                    $result_set[] = $row;
                }
            }
        }
        return $result_set;
    }
    return FALSE;
}
        $sql = "insert into users (login, pass) values (\"" . md5(rand(1, 5000) . microtime()) . "user{$i}\", \"" . md5("pass{$i}") . "\")";
        $result = bmark_query($sql, $dbh);
    }
    $timer->setMarker('MySQL_Partition');
    echo "Elapsed time between No_Partition and Code_Partition: " . $timer->timeElapsed('Code_Partition', 'MySQL_Partition') . "\n";
    // update the 3 table types
    $sql = "update users_no_partition set login = '******' where id = {$mid_id}";
    $result = bmark_query($sql, $dbh);
    $id_for_partition = $max_rows - ceil($perpart / 3);
    $sql = "update {$table} set login = '******' where id = " . $id_for_partition;
    print "sql for updating last php partition: {$sql}\n";
    $result = bmark_query($sql, $dbh);
    $sql = "update users set login = '******' where id = {$mid_id}";
    $result = bmark_query($sql, $dbh);
}
if (strcmp(bmark_type($dbh), 'drizzle') == 0) {
    $sql = "CREATE TABLE users ( id INT NOT NULL primary key AUTO_INCREMENT , login varchar(255), email varchar(255), im varchar(255), twitter varchar(255), pass varchar(255), datejoined datetime) ENGINE=InnoDB DEFAULT CHARSET=utf8";
    print "partition sql: {$sql}\n";
    $result = bmark_query($sql, $dbh);
    $sql = 'create index login_index on users (login)';
    $result = bmark_query($sql, $dbh);
    for ($i = 0; $i < $max_rows; $i++) {
        $sql = "insert into users (login, pass) values (\"" . md5(rand(1, 5000) . microtime()) . "user{$i}\", \"" . md5('pass$i') . "\")";
        $result = bmark_query($sql, $dbh);
    }
    $timer->setMarker('Drizzle_Faux_Partition');
    echo "Elapsed time between No_Partition and Code_Partition: " . $timer->timeElapsed('Code_Partition', 'Drizzle_Faux_Partition') . "\n";
    // update the 3 table types
    $sql = "update users_no_partition set login = '******' where id = {$mid_id}";
    $result = bmark_query($sql, $dbh);
    $id_for_partition = $max_rows - ceil($perpart / 3);