标签:blog os ar for on 2014 log 代码 bs
<meta charset="utf-8" />
<h1>测试批量插入mysql</h1>
<?php
set_time_limit(0);
$st= microtime(true);
$con = mysql_connect("localhost","root","111");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
mysql_query('SET UNIQUE_CHECKS=0',$con);
mysql_query('SET AUTOCOMMIT=0',$con);
for($i = 0; $i<1200; $i++) {
$sql_v = '';
$time1 = $time2 = date('Y-m-d H:i:s', time());
$sql="INSERT INTO `table_name` (id, sss) VALUES";
for($j=0; $j<1000; $j++) {
$sql_v .= " (NULL, '111'),";
}
$sql = $sql.substr($sql_v, 0, -1).';';
// echo $sql . "<br />";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
}
mysql_query('SET AUTOCOMMIT=1',$con);
mysql_query('SET UNIQUE_CHECKS=1',$con);
mysql_close($con);
$ex= microtime(true) - $st;
echo "<br />" . '时间:' . $ex. "<br />";
?>标签:blog os ar for on 2014 log 代码 bs
原文地址:http://blog.csdn.net/wide288/article/details/40586939