Search code examples
zend-frameworkzend-db-select

how to use of select with multi condition in zend framework?


i want to select rows with multi condition in zend framework how can i implement that/

1-example "select id,firstname,lastname,city from person where firstname=alex and city=xx "; 2-example "select id,firstname,lastname,city from person where firstname=alex or city=xx ";


Solution

  • $firstname = 'alex';
    $city = 'xx';
    
    // AND query
    $select = $adapter->select()
        ->from('person', array('id', 'firstname', 'lastname', 'city')
        ->where('firstname = ?', $firstname)
        ->where('city ?', $city);
    
    
    // OR query
    $select = $adapter->select()
        ->from('person', array('id', 'firstname', 'lastname', 'city')
        ->where('firstname = ?', $firstname)
        ->orWhere('city = ?', $city);
    

    Take a look at the Zend_Db_Select manual to see more examples.