JSON类型数据查询(mysql V5.0.1)
// 查询JSON类型字段 (info字段为json类型)
Db::table('think_user')->where('info$.email','[email protected]')->find();
where 和 whereOr 的使用
混合查询
where方法和whereOr方法在复杂的查询条件中经常需要配合一起混合使用,下面举个例子:
$result = Db::table('think_user')->where(function ($query) {
$query->where('id', 1)->whereor('id', 2);
})->whereOr(function ($query) {
$query->where('name', 'like', 'think')->whereOr('name', 'like', 'thinkphp');
})->select();
生成的sql语句类似于下面:
SELECT * FROM `think_user` WHERE ( `id` = 1 OR `id` = 2 ) OR ( `name` LIKE 'think' OR `name` LIKE 'thinkphp' )
EXP:表达式
支持更复杂的查询情况 例如:
where('id','in','1,3,8');
可以改成:
where('id','exp',' IN (1,3,8) ');
exp查询的条件不会被当成字符串,所以后面的查询条件可以使用任何SQL支持的语法,包括使用函数和字段名称。
系统支持的链式操作方法有: