这是在试岗时,需要用到测试数据。写的一个for循环,住mysql数据库批量添加10万条数据,这是自己写代码的开始,记录下。再过5年回头来看到这篇文章会是一种什么心情呢?
- //客户数据批量插入
- public function customer_data(){
- //执行时间不限制
- set_time_limit(0);
- $area = array('杭州','西安','成都','深圳','广州','北京','天津','上海','中山','珠海','郑州','大连');
- $ren = array('张三','李四','王五','赵六','陈功','李一','文六','刘七','司马','田七','郑五','龙三');
- $yixiang = array('低','高','一般','已合作');
- for($i=0;$i<100000;$i++){
- $tt = rand(0,90);
- $t = rand(0,23);
- $s = rand(0,59);
- $data['customer_name'] = $ren[rand(0,11)].rand(1,10000);
- $data['customer_age'] = rand(18,100) ;
- $data['customer_area'] = $area[rand(0,11)];
- $data['customer_phone'] = '1'.rand(1000000000,9999999999);
- $data['customer_genjinren'] = $ren[rand(0,11)];
- $data['customer_yixiang'] = $yixiang[rand(0,3)];
- $data['customer_time'] = date('Y-m-d H:i:s',strtotime("+$tt days $t hours $s seconds"));
- $rst = $this->Sys_customer_model->zi_add($data);
- $data = array();
- }
- echo '数据插入完成';
- }
使用的CI框架
评论