简体   繁体   English

Zend框架查询

[英]Zend Framework Query

Can anyone help me to do this in the right way?I mean.. like that : $db->select()->group..... I tried a few times, but doesn't work for me :( 任何人都可以帮助我以正确的方式执行此操作吗?我的意思是..像这样:$ db-> select()-> group .....我尝试了几次,但对我不起作用:(

$this->q->fetchAll('select * from clubs, club_photos_default where clubs.id=club_photos_default.c_id group by clubs.id'); $ this-> q-> fetchAll('从俱乐部中选择*,club_photos_default其中clubs.id = club_photos_default.c_id由clubs.id分组');

Best Regards, 最好的祝福,

The right way in this case is the way you're doing it, since the whole SQL query is known and static. 在这种情况下,正确的方法就是您执行操作的方法,因为整个SQL查询是已知的且是静态的。

You are not required to use Zend_Db_Select to build queries procedurally. 您不需要使用Zend_Db_Select来以过程方式构建查询。 In fact, it's often more complex and less readable than just typing out the literal SQL query. 实际上,它通常比仅键入文字SQL查询更为复杂且可读性较低。

Use Zend_Db_Select when you need to build a query procedurally, based on variables and logic in your application code. 当您需要基于应用程序代码中的变量和逻辑以过程方式构建查询时,请使用Zend_Db_Select

But to answer your question, this should work: 但是要回答您的问题,这应该可以:

$select = $db->select()
  ->from(array('c'=>'clubs'))
  ->join(array('p'=>'club_photos_default'), 'c.id=p.c_id')
  ->group('c.id');
$this->q->fetchAll($select);

(Assuming $db is an object of Zend_Db_Adapter .) (假设$dbZend_Db_Adapter的对象。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM