Zend Framework: how to make a DB choice with multiple parameters?

I'm just wondering what the syntax is to make a db choice in the Zend Framework, where the two values ​​are true. Example: I want to find if the user is already a member of a group:

$userId = 1; $groupId = 2; $db = Zend_Db_Table::getDefaultAdapter(); $select = new Zend_Db_Select($db); $select->from('group_members') ->where('user_id = ?', $userId); //Right here. What do I do about group_id? $result = $select->query(); $resultSet = $result->fetchAll(); 
+6
zend-framework zend-db zend-db-select
source share
2 answers

By default, you can use several where clauses to be combined together:

 $select->from('group_members') ->where('user_id = ?', $userId) ->where('group_id = ?', $groupId); 
+15
source share

Just in case someone wants to add an OR condition to select with multiple options

 $select = $db->select() ->from('products', array('product_id', 'product_name', 'price')) ->where('price < ?', $minimumPrice) ->orWhere('price > ?', $maximumPrice); 

For a larger view of the Zend Selection Guide Docs: zend.db.select

+4
source share

All Articles