views:

108

answers:

1

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

$table = $this->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?

+6  A: 

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);
Justin Swartsel
It is working. Thanks.
NAVEED