开发者

Zend Framework: How to do a DB select with multiple params?

开发者 https://www.devze.com 2022-12-13 09:21 出处:网络
I\'m just wondering what the syntax is to do a db select in Zend Framework where two values are true. Example: I want to find if a user is already a member of a group:

I'm just wondering what the syntax is to do a db select in Zend Framework where two values are true. Example: I want to find if a 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();


You can use multiple where clauses which will be ANDed together by default:

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


Just In case someone wants to add an OR condition to a select with multiple params

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

For more view the Zend Select manual Docs: zend.db.select

0

精彩评论

暂无评论...
验证码 换一张
取 消