<?php
/***************************************************************
* (c) 2006-2007 Askywhale (hosting[a]askywhale.com)
* All rights reserved
*
* This script is part of HostingBenchmark.com. This project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
***************************************************************/
define('MYSQLTEST_BASE_ITERATIONS',1);
class MysqlTest extends AbstractTest {
var $txtResult;
function getTitle(){ return "Mysql Base Test"; }
function getDescription(){ return "Benchmark connection, CREATE, INSERT, SELECT, DROP on a MySQL ISAM database"; }
function getRelease(){ return 1; }
function isBenchmark(){ return true; }
function getParametersForm(){
foreach($_SESSION['tests'] as $test) {
if(strtolower(get_class ($test))=='mysqltest')
$params = $test->parameters;
}
if(!isset($params))
$params = array('server'=>'localhost','port'=>'3306',
'username'=>'root', 'password'=>'', 'database'=>'mysql');
return "Server : <input type='text' name='server' value='".$params['server']."' /><br />".
"Port : <input type='text' name='port' value='".$params['port']."' /><br />".
"Username : <input type='text' name='username' value='".$params['username']."' /><br />".
"Password : <input type='text' name='password' value='".$params['password']."'' /><br />".
"Existing database : <input type='text' name='database' value='".$params['database']."'' /><br />";
}
function getCreateSql() {
return "CREATE TABLE IF NOT EXISTS clapiotes (".
"id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,".
"size DOUBLE NOT NULL ,".
"voice TEXT NOT NULL ,".
"position VARCHAR( 15 ) NOT NULL) TYPE=MyISAM";
}
function doTest(){
$this->txtResult = OK_STR;
if(!function_exists('mysql_connect')) {
$this->txtResult = "mysql_x functions not available";
return;
}
$server = $this->parameters['server'];
if(is_numeric($this->parameters['port']))
$server .=':'.$this->parameters['port'];
for($i=0;$i<MYSQLTEST_BASE_ITERATIONS;$i++) {
$c = @mysql_connect($server,$this->parameters['username'],
$this->parameters['password']);
if($c===false) {
$this->txtResult = "Failed mysql_connect() : ".mysql_error();
return;
}
if(@mysql_select_db($this->parameters['database'])===false) {
$this->txtResult = "Failed mysql_select_db() : ".mysql_error();
return;
}
if(@mysql_query($this->getCreateSql() ,$c)==false) {
$this->txtResult = "Failed mysql_query('create table...') : ".mysql_error();
return;
}
for($j = 0;$j<20;$j++) //50%
@mysql_query("INSERT INTO clapiotes ".
"VALUES ('',".(($j%3)/10).",'".md5($j)."','".chr(90-$j%24)."')",$c);
for($j = 0;$j<2000;$j++) { //25%
$res = @mysql_query("SELECT * FROM clapiotes ORDER BY ".rand(1,4)." DESC",$c);
while(mysql_fetch_row($res));
}
if(@mysql_query("DROP TABLE clapiotes",$c)==false) {
$this->txtResult = "Failed mysql_query('drop table...') : ".mysql_error();
return;
}
@mysql_close($c);
}
}
function getTxtResults(){
return $this->txtResult;
}
}
?>