Rqgg Page 1/2

excitingwonderlakeInternet και Εφαρμογές Web

13 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

85 εμφανίσεις

like in where query in zend framework 2
Asked by
OSSCube Solution
on 2013-03-22T11:33:56-04:00
I am using the Zend framework 2.x and facing the problem as I have search a lot. I want to use the
like clause in query but each time gives the errors:

Here is my efforts:


$sql = new Sql($this->adapter); $select = $sql->select()->columns( array('user_profile_id',
'profile_login_name'))->from($this->table)->where->like( 'profile_login_name', '%'.$strSearch.'%');
echo $select->getSqlString(); die;
but this gives the error:


Fatal error: Call to undefined method Zend\Db\Sql\Where::getSqlString() in
/var/www/YAAB/branches/admin/models/Model/UserTable.php on line 131



I have also used the Zend\Db\Sql\Predicate but this also gives the error.

So my question are that



how to use the like clause in query in zend framework 2?

What is problem in my code?

Please
reply soon as it is urgent.

Best Answer
Answer by
Andrew
on 2013-03-22T11:52:33-04:00
Try this out


$select = $sql->select(); // or new Select('table'); $where = new \Zend\Db\Sql\Where();
$where->addPredicate( new \Zend\Db\Sql\Predicate\Like('my_field', '%test%') );
$select->where($where); // this part will depend on if you're using TableGateway or what ever
$stmt = $sql->prepareStatementForSqlObject($select); $resultSet = new ResultSet();
$resultSet->initialize($stmt->execute());
Archives
Technology
Programmers
Mar 22nd, 2013
Week 12, 2013
March, 2013
Related
Rails Eager Loading and where clause
group by column to get the row with largest value of a column
mySQL - variable in like clause
Insert only if id doesnt exist
Group by clause to get name of highest paid employee
Set Parameter with TableGateway Select Function show error undefined variable
Rqgg
Page 1/2
like in where query in zend framework 2
SQL DISTINCT clause with WHERE
How to put special tags for each form element?
How to use index in SQL query
PLSQL or SSRS, How to select having all values in a group?
View Online
http://www.rqgg.net/topic/xktp-like-in-where-query-in-zend-framework-2.html
Rqgg
Page 2/2