Search code examples
phpdatabasezend-frameworkselectjoin

Select join two tables with Zend DB


I have 2 tables: users and user_profile:

users: (user_id, email, password, created_date)

user_profile: (user_id, first_name, last_name, address, birthday)

Using Zend DB select I want to join these two tables (like this)

INNER JOIN `users` ON `users`.`user_id`=`user_profile`.`user_id`

The problem now is I don't know how to achieve this with Select join by using Zend_Db. Please help me out. Thank you so much!!!


Solution

  • $select = $this->select()
                    ->from('users')
                    ->joinLeft(array('userprofile'=>'user_profile'),'users.user_id = userprofile.user_id')
                    ->where('users.user_id = ?', 1);   
    

    This is how you join two tables in zend. Check the ZF manual for advances usages of the zend join zend.db.select.building.join