其他分享
首页 > 其他分享> > tp5的新增和批量新增

tp5的新增和批量新增

作者:互联网

<?php
namespace app\index\controller;
use app\index\model\User as UserModel;
class User{
    //tp5的新增数据
    public function add(){
        /*$user = new UserModel(); 
        $user ->name = '张三';
        $user ->email = 'zhang@qq.com';
        $user ->birthday = strtotime('1989-7-11');
        if ($user->save()){
            return'成功';
        }else{
            return'失败';
        }*/
        /*
        $user['name']= '看云';
        $user['email'] = 'kanyun@qq.com';
        $user['birthday'] = strtotime('1999-1-1');
        if (UserModel::create($user)){
            return'成功';
        }else{
            return'失败';
        }*/
    }
    //tp5的批量新增数据
    public function addList(){
        $user = new UserModel();
        $list = [
            [
                'name'=>'流云','email'=>'liuyun@qq.com','birthday'=>strtotime('1999-1-1')
            ],
            [
                'name'=>'流云1','email'=>'liuyun1@qq.com','birthday'=>strtotime('1998-1-1')
            ]
        ];
        if($user->saveAll($list)){
            return'成功';
        }
        else{
            return'失败';
        }
    }
}

 

标签:qq,return,批量,新增,strtotime,tp5,birthday,user,email
来源: https://www.cnblogs.com/lqh123/p/16597218.html