开发者

How to write this query with Zend Framework?

How can I write this query with Zend Framework?

select
    log.log_date,
    log.user_id,
    log.task,
    log.work_desc,
    log.hours,
    log.user2project,
    project.title as t开发者_开发问答itle,
    project.id
from 
    log,
    project
where
    log.user2project = project.id


This is pretty much what you want.

$select = $this->select()
                ->setIntegrityCheck(false)
                ->from('log', array('log_date', 'user_id', 'task', 'work_desc', 'hours', 'user2project'))
                ->join('project', 'log.user2project = project.id', array('title' => 'title', 'id'));

The code above just creates the Zend_Db_Table_Select object, it doesn't run the query. To run the query you will have to do the following:

$result = $this->fetchAll($select); //this results in a Zend_Db_Table_Rowset
//if you want to return an array, just do
return $result->toArray();
//if you want the rowset object just
return $result;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜