开发者

Zend: How to use SQL query with 'like' keyword?

I am using zend framework. I am using following query in zend and it is working for me perfectly.

$table = $this->开发者_JAVA技巧getDbTable();
$select = $table->select();
$select->where('name = ?', 'UserName');
$rows = $table->fetchAll($select);

Now I want to create another query in zend with 'like' keyword. In simple SQL it is like that.

SELECT * FROM Users WHERE name LIKE 'U%'

Now how to convert my zend code for above query?


Try:

$table = $this->getDbTable();
$select = $table->select();
$select->where('name LIKE ?', 'UserName%');
$rows = $table->fetchAll($select);

or if UserName is a variable:

$table = $this->getDbTable();
$select = $table->select();
$select->where('name LIKE ?', $userName.'%');
$rows = $table->fetchAll($select);


$user = new Application_Model_DbTable_User();
// User List
$uname=$_POST['uname'];

$query = $user
    ->select()
    ->where('firstname LIKE ?', $uname.'%')
    ->ORwhere('lastname LIKE ?', $_POST['lname'].'%')
    ->ORwhere('emailid LIKE ?', $_POST['email'].'%');

$userlist = $user->fetchAll($query);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜