typecho插件等联合查询数据库以及联合多个表查询
联合查询数据库,用到的是join
首先要知道,是怎么查询的
我们可以看到下方代码(联合查询两个表)
$query = $db->select()
->from('table.contents')
->join('table.comments', 'table.contents.cid = table.comments.cid',Typecho_Db::LEFT_JOIN)
->where('table.contents.type = ?', 'post');
echo $query;
//SELECT * FROM typechocontents LEFT JOIN typecho_comments ON typecho_contents.`cid` = typecho_comments.`cid` WHERE (typecho_contents.`type` = 'post' )
三个表联合查询,代码如下
$db->select()->from('table.contents')->join('table.comments', 'table.contents.cid = table.comments.cid',Typecho_Db::LEFT_JOIN)->join('table.metas', 'table.comments.cid = table.metas.mid',Typecho_Db::LEFT_JOIN)
声明:本站原创文章文字版权归本站所有,转载务必注明作者和出处;本站转载文章仅仅代表原作者观点,不代表本站立场,图文版权归原作者所有。如有侵权,请联系我们删除。