1、Table方法:定义要操作的数据表名称,可以动态改变当前操作的数据表名称,需要写数据表的全名,包含前缀,可以使用别名,例如:
$Model->Table('think_user user')
->where('status>1')
->select();
$Model->table('think_blog blog,think_type type')
->where('blog.typeid=type.id')
->field('blog.id as id,blog.title,blog.content,type.typename as type')
->order('blog.id desc')
->limit(5)
->select();
$Model->Table(array('think_user'=>'user','think_group'=>'group'))
->where('status>1')
->select();
$Model->join('work ON artist.id = work.artist_id')
->join('card ON artist.card_id = card.id')
->select();
//Left Join
$Model->table('user U')->join('news N on U.id=N.cid')
->field('U.*,N.*')
->order('id desc')
->limit('8')
->findall();
$Model->join('RIGHT JOIN work ON artist.id = work.artist_id')
->select();
//Right Join
$Model->table('user U')
->join(array('right','news N on U.id=N.cid'))
->field('U.*,N.*')
->order('id desc')
->limit('8')
->findall();
$Model->join(array(' work ON artist.id = work.artist_id','card ON artist.card_id = card.id'))
->select()
echo $Model->getLastSql();//打印一下SQL语句,查看一下