模型操作
插入一条数据
$ar = [];
for ($i = 0; $i < 100; $i++) {
$ar[] = [
'name' => 'name' . $i,
'email' => 'name' . $i . '@aa.com',
'age' => rand(10, 70)
}
User::insert($ar, true);
更新数据
$row = User::whereIn('id', [61, 71, 81])->delete();
echo $row . PHP_EOL;// 影响行数
$one = User::find(66);
查询
// select * from users left join articles on users.id=articles.user_id where users.id>1
$arr = User::where('users.id', '>', '1')->leftJoin('articles', 'users.id', 'articles.user_id')->findAll()->toArray();
// select * from users left join articles on users.id=articles.user_id and articles.read_count>2 where users.id>1
$arr = User::where('users.id', '>', '1')->leftJoin('articles', function (Join $q) {
})->findAll()->toArray();