如何使用Zend Framework编写此查询?
select log.log_date, log.user_id, log.task, log.work_desc, log.hours, log.user2project, project.title as title, project.id from log, project where log.user2project = project.id
答案 0 :(得分:3)
这就是你想要的。
$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'));
上面的代码只是创建Zend_Db_Table_Select
对象,它不运行查询。要运行查询,您必须执行以下操作:
$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;