|
When we use Zend_DB_Table_Abstract fetchAll($where, $order) to get all the records from table. In the where clause, if we have several condition, for example, condition1, condtion2, condition3. How do we put all these conditions in the where clause? Thank in advance.
|
|
$sql = "select * from sometable where id = ?" $data = 1; FetchAll ($sql, $data) Would replace the ? with the vaule of 1. It gets more advanced eaiser to just look at the manual verses me pasting it here. see http://framework.zend.com/manual/en/zend.db.select.html -----Original Message----- From: Kexiao Liao [mailto:[hidden email]] Sent: Wednesday, December 12, 2007 11:15 AM To: [hidden email] Subject: [fw-general] fetchAll($where, $order) When we use Zend_DB_Table_Abstract fetchAll($where, $order) to get all the records from table. In the where clause, if we have several condition, for example, condition1, condtion2, condition3. How do we put all these conditions in the where clause? Thank in advance. -- View this message in context: http://www.nabble.com/fetchAll%28%24where%2C-%24order%29-tp14298290s16154p14 298290.html Sent from the Zend Framework mailing list archive at Nabble.com. |
$sql = "select * from sometable where id = ?" Would replace the ? with the vaule of 1. Actually that's not true - the signature for fetchAll in Zend_Db_Table uses an already-resolved string for the 'WHERE' clause.
If you want to utilise a number of placeholders from within a Zend_Db_Table you can approach it a number of ways, but here's two simple examples:- Currently $db = $this->getAdapter(); $where = array($db->quoteInto('id = ?', $id), $db->quoteInto('condition2 = ?', $foo), $db->quoteInto('condition2 = ?', $foo)); $rowSet = $this->fetchAll(join(' AND ', $where), $limit); // Assumes $limit is already set elsewhere New Zend_Db_Table class in incubator $select = $this->select()->where('id = ?', $id) ->where('condition2 = ?', $foo) ->where('condition3 = ?', $bar) ->limit($limit); $rowSet = $this->fetchAll($select); Named placeholders are also being considered for the Zend_Db_Select component but not yet available. Cheers
-- Simon Mundy | Director | PEPTOLAB """ " "" """""" "" "" """"""" " "" """"" " """"" " """""" "" " PeptoLab will be closed: Saturday 15th December through until Monday 17th December Saturday 22nd December through until Wednesday 2nd January For urgent requests, please call 0438 046 061 202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000 Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654 4124 |
|
> Actually that's not true - the signature for fetchAll in Zend_Db_Table uses an already-resolved string for the 'WHERE' clause. Right, I see I missed the "in Zend_Db_Table" in the question. Good to know. :)
From: Simon Mundy
[mailto:[hidden email]] $sql = "select * from sometable where id = ?" Would replace the ? with the vaule of 1. Actually that's not true - the signature for fetchAll in Zend_Db_Table uses
an already-resolved string for the 'WHERE' clause.
If you want to utilise a number of placeholders from within a Zend_Db_Table
you can approach it a number of ways, but here's two simple examples:-
Currently
$db =
$this->getAdapter();
$where =
array($db->quoteInto('id = ?', $id),
$db->quoteInto('condition2 = ?', $foo),
$db->quoteInto('condition2 = ?', $foo));
$rowSet = $this->fetchAll(join('
AND ', $where), $limit); // Assumes $limit is already set elsewhere
New Zend_Db_Table
class in incubator $select =
$this->select()->where('id = ?', $id)
->where('condition2 = ?', $foo)
->where('condition3 = ?', $bar)
->limit($limit);
$rowSet =
$this->fetchAll($select);
Named placeholders are also being considered for the Zend_Db_Select
component but not yet available.
Cheers
--
Simon Mundy | Director | PEPTOLAB
""" " "" """""" "" "" """"""" " "" """"" " """"" " """""" "" "
PeptoLab will be closed:
Saturday 15th December through until Monday 17th
December
Saturday 22nd December through until Wednesday 2nd January
For urgent requests, please call 0438 046 061 202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654
4124
|
| Powered by Nabble | Edit this page |
