注意事项
一:sql 语句的字符串的长度
二:插入前要关闭游标再插入
Warning: PDOStatement::execute(): MySQL server has gone away 错误发生的时候调整下 j 的最大值即可
关键代码:
分析,通过循环来添加数据,若出现
$db = mysql::getInstance();
$num = 1;
for($i = 1; $i <= 3 ; $i++) {
$sql = "insert into table_name (user_id, min, status) VALUES ";
for($j = 1 ; $j <= 10000; $j++) {
$user_id = $num + 70022;
if ($j == 10000) {
$sql .= "($user_id, 60, 1)";
} else {
$sql .= "($user_id, 60, 1),";
}
$num ++;
}
$db->query($sql);
$db->close();
}
/********************** mysql 类 *************/
class mysql {
static protected $instance = null;
//声明数组存放数据
private $data=array();
//pdo对象
private $db=NULL;
//表名
protected $table = '';
protected $rootDir;
//pdostatement类对象
protected $stms = null;
final protected function __construct(){