In my model:
$rowset = $this->tableGateway->select(array('username' => $identifier));
$row = $rowset->current();
return $row;
It executes the following query:
SELECT * FROM member WHERE username='<< ENTERED VALUE >>';
but I want execute the following query:
SELECT * FROM member WHERE username='<< ENTERED VALUE >>' OR id_customer='<< ENTERED VALUE >>';
What are the changes I have to make in model file?
And please suggest useful blog regarding this. I cant find answer for this in ZF2 Documentation.
The easiest way to do so is using the explicit OR
keyword:
$where = new Zend\Db\Sql\Where;
$where->equalTo( 'username', $identifier );
$where->OR->equalTo( 'id_customer', $customerId );
$rowset = $this->tableGateway->select( $where );
$row = $rowset->current();
return $row;
A little late to the party, but for thoroughness I thought I'd provide an alternative that worked quite well for me, and one that might be a little easier to implement for some developers:
// '$gateway' is a Zend\Db\TableGateway\TableGateway object...
$search_string = 'something';
$select = $gateway->select(function($select) use($search_string) {
$select->where->OR->like('first_name', '%'. $search_string .'%');
$select->where->OR->like('last_name', '%'. $search_string .'%');
});
After running that, $select
will be holding your result set, ready to loop through.
Hope this helps someone! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With