lumen DW::raw()方法,原样输出括号中的sql
DB::table('sms_code')
->insert([
'telephone' => $telephone,
'mode' => $operate,
'created_at' => DB::raw('NOW()'),
'status' => 1
]);
NOW()方法为mysql方法,php无法运行,此处原样输出
mysql> select NOW();
2018-09-18 14:43:24
mysql> select date_add( NOW(), interval 5 minute );
// 五分钟后
2018-09-18 14:52:48
```
CURRENT_DATE() 方法为日期方法
mysql> SELECT CURRENT_DATE;
2018-09-19
laravel多条件组合查询
$users = DB::table('users')->where([
['status', '=', 1],
['subscribed', '<>', 1]
])
->orWhere(…)
->get();
lumen门面查询返回值
DB::table()->insert 插入成功返回值 true
DB::table()->update 修改成功返回影响行数
连表多条件查询
并且关系 &&
$roomUuid = 1;
$chatInfo = DB::table('chat_info')
->where('chat_info.room_uuid', $roomUuid)
->leftJoin('user_rooms', function ($join) {
$join->on('user_rooms.user_uuid', '=', 'chat_info.user_uuid')
->on('user_rooms.room_uuid', '=', 'chat_info.room_uuid');
})
或者关系 ||
$roomUuid = 1;
$chatInfo = DB::table('chat_info')
->where('chat_info.room_uuid', $roomUuid)
->leftJoin('user_rooms', function ($join) {
$join->on('user_rooms.user_uuid', '=', 'chat_info.user_uuid')
->orOn('user_rooms.room_uuid', '=', 'chat_info.room_uuid');
})
多条件查询
$roomUuid = 1;
$chatInfo = DB::table('chat_info')
->where('chat_info.room_uuid', $roomUuid)
->leftJoin('user_rooms', function ($join) use ($chatInfo) {
$join->on('user_rooms.user_uuid', '=', 'chat_info.user_uuid')
->where('user_rooms.room_uuid', '=', $chatInfo);
})
laravel加载文件
vendor/laravel/lumen-frameword/src/appcation.php 为框架加载文件
getConfigurationPath方法会加载系统配置文件
$app->configure('文件名'); 可加载自定义指定配置