Quantcast

fetchAll($where, $order)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

fetchAll($where, $order)

Kexiao  Liao
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: fetchAll($where, $order)

Terre Porter
 
$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.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: fetchAll($where, $order)

Simon Mundy
$sql = "select * from sometable where id = ?"
$data = 1;

FetchAll ($sql, $data)

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


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.

--

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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: fetchAll($where, $order)

Terre Porter

> 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. :)

But the code does work when using a Zend_Db_Adapter. 


From: Simon Mundy [mailto:[hidden email]]
Sent: Wednesday, December 12, 2007 4:50 PM
To: Terre Porter
Cc: [hidden email]
Subject: Re: [fw-general] fetchAll($where, $order)

$sql = "select * from sometable where id = ?"
$data = 1;

FetchAll ($sql, $data)

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


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.

--

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

Loading...