模型操作

    插入一条数据

    1. $ar = [];
    2. for ($i = 0; $i < 100; $i++) {
    3. $ar[] = [
    4. 'name' => 'name' . $i,
    5. 'email' => 'name' . $i . '@aa.com',
    6. 'age' => rand(10, 70)
    7. }
    8. User::insert($ar, true);

    更新数据

    1. $row = User::whereIn('id', [61, 71, 81])->delete();
    2. echo $row . PHP_EOL;// 影响行数
    3. $one = User::find(66);

    查询

    1. // select * from users left join articles on users.id=articles.user_id where users.id>1
    2. $arr = User::where('users.id', '>', '1')->leftJoin('articles', 'users.id', 'articles.user_id')->findAll()->toArray();
    3. // select * from users left join articles on users.id=articles.user_id and articles.read_count>2 where users.id>1
    4. $arr = User::where('users.id', '>', '1')->leftJoin('articles', function (Join $q) {
    5. })->findAll()->toArray();