2009年9月29日星期二

RE: [fw-db] Support Zend_Db_Select sub selects ?

I do it almost the same way. The only difference to Hector’s solution is that I use the actual select object in the new select statement instead of converting it to a string. This works very well for me.

 

$subSelect = $db->select()

->from('aktualne', array('n' => 'name'));

 

$select = $db->select()

->from(

    array('akt' => $subSelect),

    array('n')

)

->where('akt.n = ?', 2008);

 

Gina-Marie Rollock

 

From: Hector Virgen [mailto:djvirgen@gmail.com]
Sent: Tuesday, September 29, 2009 12:02 PM
To: sNop
Cc: fw-db@lists.zend.com
Subject: Re: [fw-db] Support Zend_Db_Select sub selects ?

 

You should be able to do that if you wrap your subselect in a Zend_Db_Expr object. Try this:

 

$subSelect = $db->select()

->from('aktualne', array('n' => 'name'));

 

$subSelectString = '(' . $subSelect->__toString() . ')';

 

$select = $db->select()

->from(

    array('akt' => new Zend_Db_Expr($subSelectString)),

    array('n')

)

->where('akt.n = ?', 2008);

 

$db->fetchAll($select);


--
Hector

2009/9/29 sNop <snop3@seznam.cz>

Hi,

something like this:
SELECT `akt`.`n`
FROM (
 SELECT `name` AS `n`
 FROM `aktualne`
) AS `akt`
WHERE `akt`.`n` = '2008'

Support this Zend_Db_Select ?

Thank for any suggestions.

 

没有评论: