简体   繁体   中英

OR WHERE in zend framework

How can I write query like this In Zend Framework and fetch all the rows

SELECT * FROM tbl
WHERE user_id = $part_mail
OR user_id ='$id3';

I used to try this :

    $select = $tigaseModel->fetchAll($tigaseModel
                                        ->select()
                                        ->where('user_id = ?', $part_mail )
                                        -> orwhere('user_id = ?', $id3 )); 

Following ways should help you.

Solution 1 :

where( "user_id = '$part_mail' OR user_id = '$id3'" );

Solution 2 :

$list = array( $part_mail, $id3 );
...
where( 'user_id in ( ? )', $list );

Solution 3 :

$list = array( $part_mail, $id3 );
...
where( array( 'user_id' => $list ) );

Refer to Documentation :
Example #17 Example of an array parameter in the where() method
-You can pass an array as the second parameter to the where() method when using the SQL IN operator.

orwhere available in Zend Framework 1. But there is a space in your code before orwhere(). Check the code below:

$select = $tigaseModel->fetchAll($tigaseModel
                                    ->select()
                                    ->where('user_id = ?', $part_mail )
                                    ->orwhere('user_id = ?', $id3 )); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM