ThinkPHP提供了数据的动态查询方法,可以简化你的查询代码,例如:
$User->where(‘name=”ThinkPHP”‘)->find();
可以简化为:
$User->getByName(‘ThinkPHP’);
$User->where(‘email=”thinkphp@qq.com”‘)->find();
可以简化为:
$User->getByEmail(‘thinkphp@qq.com’);
getBy**** 方法里面的**** 会转换成小写的字段名,如果字段不存在,就会出错。
如果你的字段名是user_id ,那么查询方法应该写成:
$User->getByUserId(5);
UserId 会被解析成为数据库的user_id字段,这点需要注意,以免引起不必要的麻烦。
目前尚不支持,对多个字段的动态查询。
很不错的功能