在网站里面功能都是取出数据,这时候用到查询语句,select() 方法,也有用find(),下面详细说说查询几种方式
1,使用字符串作为查询条件
$User = M("User"); // 实例化User对象
$User->where('type=1 AND status=1')->select();
2,使用数组作为查询条件
$User = M("User"); // 实例化User对象
$condition['name'] = 'thinkphp';
$condition['status'] = 1;
// 把查询条件传入查询方法
$User->where($condition)->select();
3,使用对象方式来查询
$User = M("User"); // 实例化User对象
// 定义查询条件
$condition = new stdClass();
$condition->name = 'thinkphp';
$condition->status= 1;
$User->where($condition)->select();
注意,最常用的方式为字符串和数组的形式
文章来自 www.huthon.com