qeephp---读取csv文件并进行写入到数据库

$filename = 'Grouposts_AddUsers.csv';
        $handle = fopen($filename, 'r');
        $row = 1;
        while($data = fgetcsv($handle,'1000',',')){
            $firstname = $data['1'];
            $lastname = $data['2'];
            $username = $data['3'];
            $password = $data['4'];
            $userArr = array(
                'firstname'=>$firstname,
                'lastname'=>$lastname,
                'username'=>$username,
                'passwd'=>$password,
                'createtime'=>$_SERVER['REQUEST_TIME']
            );
            $userObj = new User($userArr);
            $userObj->save();
            $userId = $userObj->id();
            $email = "[email protected]";
            $userHasEmail = array(
                'user_id'=>$userId,
                'group_id'=>0,
                'email'=>$email,
                'email_default'=>1
            );
            $userHasObj = new Userhasemail($userHasEmail);
            $userHasObj->save();

        }
        fclose($handle);
        exit;


你可能感兴趣的:(qeephp---读取csv文件并进行写入到数据库)