public function test_mysql($loop_times, $sql = NULL) { $tbname = $this->tbname; $dbname = $this->dbname; $start_time = microtime(true); if ($sql == NULL) { $sql = sprintf("select * from %s", $ops->getTBname()); } for ($i = 0; $i < $loop_times; $i++) { $ops = new dbops(); $ops->setTBname($tbname); $ops->setDBname($dbname); ##$start=$i*rand(1,950); # more then 2w $start = $i * 128; $conditions = sprintf("idx > %d and idx < %d;", $start, $start + 1000); $sql = sprintf("select * from %s where %s", $tbname, $conditions); $data = $ops->query($sql); $ops->close(); } $end_time = microtime(true); $dbtime = $end_time - $start_time; return $dbtime; }
* class and functions */ #require_once('mysql_info.php'); require_once 'dbops.php'; require_once 'iredis.php'; echo "数据库测试页面\n <br/>"; date_default_timezone_set('PRC'); echo "当前时间:" . date("Y-m-d H:i:s") . "<br/>"; echo "数据库表如下:<br/>"; ## following show the mysql database operation $ops = new dbops(); #$ops->setDBname("greentea"); # change database #$ops->setTBname("light_app"); $sql = sprintf("select * from %s", $ops->getTBname()); $data = $ops->query($sql); $ops->close(); ## show the $data in a form $rows = count($data); $cols = count($data[0]) / 2; # two kinds of index: id and type #$cols=count($data[0]); $td_width = floor(100 / $cols) . "%"; $tab_str = "<table border=\"1\" width=\"80%\" align=\"left\">\n"; var_dump($data); for ($i = 0; $i < $rows; $i++) { $tab_str .= "<tr>\n"; $row_i = $data[$i]; for ($k = 0; $k < $cols; $k++) { $tab_str .= "<td width=\"{$td_width}\">{$row_i[$k]}</td>\n"; } $tab_str .= "</tr>\n";