当前位置:Gxlcms > 数据库问题 > 测试数据库

测试数据库

时间:2021-07-01 10:21:17 帮助过:11人阅读

= "localhost"; $username = "root"; $password = "121212"; // 建立数据库连接 $link = @mysql_connect($localhost, $username, $password); // 创建测试数据库 $sql = "CREATE DATABASE IF NOT EXISTS test"; @mysql_query($sql, $link); // 选择数据库 $sql = "USE test"; $res = @mysql_query($sql, $link); // 创建测试表 $sql="CREATE TABLE IF NOT EXISTS `test` ( `id` INT NOT NULL AUTO_INCREMENT , `number` INT NOT NULL , `string` VARBINARY(64) NOT NULL , `msg` TEXT NOT NULL , PRIMARY KEY (`id`) ) ENGINE = InnoDB CHARSET=utf8 COLLATE utf8_general_ci;"; @mysql_query($sql, $link); // 插入数据 $insert_num = 5000; // 单位:万 $start_time = microtime(true); for ($i=0; $i<$insert_num; ++$i) { // 使用事务快速插入 $sql = "BEGIN"; @mysql_query($sql, $link); for ($j=0; $j<10000; ++$j) { $number = rand(1, 2000000000); $string = md5($number); $msg = strval($number).$string; $sql = "INSERT INTO `test`(`number`, `string`, `msg`) VALUES ({$number},‘{$string}‘,‘{$msg}‘)"; @mysql_query($sql, $link); } $sql = "COMMIT"; @mysql_query($sql, $link); } $end_time = microtime(true); echo "插入{$insert_num}万条数据,用时:".($end_time-$start_time)."".PHP_EOL; ?>

 

 

 

 

 

 

 

 

 

 

 

 

    

测试数据库

标签:com   数据   eol   单位   快速   null   gen   char   utf8   

人气教程排行