hottehead
hottehead

Reputation: 43

SQL Subquery in Zend Framework 1.12

Im writing a query which has a subquery in Zend Framework 1.12. I am almost finished but encounter a strange behaviour. These are my queries

    $subquery = $db->select()
                    ->from('project')
                    ->reset( Zend_Db_Select::COLUMNS )
                    ->columns('project_id')
                    ->where('user_id = ? ', $iUserId);

    $select = $db->select()
                    ->from('user2project')
                    ->reset( Zend_Db_Select::COLUMNS )
                    ->columns('user_id')                        
                    ->where( 'project_id IN (?)', $subquery->assemble() );

And this is the resulting SQL statement:

$select->assemble() produces

string(143) "SELECT `user2project`.`user_id` FROM `user2project` WHERE (project_id IN ('SELECT `project`.`project_id` FROM `project` WHERE (user_id = 6 )'))"

The subquery is quoted like this ' SUBQUERY ' . The DB seems to take this as an array element and does not resolve the select. What do I have to change in my Zend query to get rid of these quotes?

Upvotes: 1

Views: 943

Answers (1)

Maksym Karazieiev
Maksym Karazieiev

Reputation: 111

You shouldn't use ->assemble(). If you'll remove assemble() you won't need Zend_DB_Expr as well.

Upvotes: 1

Related Questions