Skip to content
Advertisement

How to write a like query in Zend Framework 2

I have created a select query that functioning well. But now I need to change this to a like query. Can anyone tell me the correct way?

This is my select query structure ->

public function getSelectedHotel($id)
{
    $selectedHotel = $this->tableGateway->select(['hotel_id' => $id]);

        return $selectedHotel;
}

When I code like this it gives me this error.

Code ->

$hotelsByYear = $this->tableGateway->select()->where('date_added like ?',$year.'%');

Error ->

Fatal error: Uncaught Error: Call to undefined method ZendDbResultSetResultSet::where() in

Advertisement

Answer

Please try below code OR refer the official document.

$where = new Where();    
$where->like('Field_Name', '%'.$ParamVal.'%');
//use as below
$this->tableGateway->select($where);

Don’t forget to use ZendDbSqlWhere;

Hope this helps

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement