0

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 title,
    project.id
from 
    log,
    project
where
    log.user2project = project.id
0

1 Answer 1

3

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;
Sign up to request clarification or add additional context in comments.

3 Comments

its returned me a huge array that is describing about whole schema.... But where are the values that this query should returned
@Awais Qarni : that's the object. If you want an array and not an object you have to call toArray() method on your result
@Awais Qarni: toArray() is a method you can call on a Zend_Db_Table_Rowset (aka a result object).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.