Blogger Information
Blog 29
fans 0
comment 0
visits 34524
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
tp5.1 批量插入数据库
徐郭鹏的博客
Original
3483 people have browsed it
public function index(){
    $array = array();//定义数组
    for($a=0;$a<100000;$a++){
        $numebr = rand(6, 10);
        $code = $this->createNonceStr($numebr);
        $array[$j]['code'] = $code;
    }
    $num = 100;//每次导入条数
    $limit = ceil(count($array)/$num);
    for($i=1;$i<=$limit;$i++){
        $offset=($i-1)*$num;
        $data = array_slice($array,$offset,$num);
        $result = model('codeList')->insertAll($data);
    };
}
//生成随机字符
private function createNonceStr($length = 10) {
    $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
    $str = "";
    for($i = 0; $i < $length; $i ++) {
    $str .= substr ( $chars, mt_rand ( 0, strlen ( $chars ) - 1 ), 1 );
    }
    return $str;
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post