2009年6月17日星期三

Re: [fw-db] fetchCol() not returning results

Ian Munday wrote:
>
> I'm having problems getting fetchCol() to work as expected. I'm trying to
> execute the following code, but getting nothing back even though there is
> data in the database. No errors are reported to the log file:
>
> <?php
> ...
> $db = $this->getAdapter(); // MYSQLI
> $sql = 'SELECT name FROM countries ORDER BY name';
> $rows = $db->fetchCol($sql);
> Zend_Debug::dump($rows, '$rows');
> ...
> ?>
>
> Any one spot what I'm doing wrong with fetchCol()?
>
> Regards,
> Ian
>

Have you tried to do

$db->setFetchMode(Zend_Db::FETCH_COLUMN);
$sql = 'SELECT name FROM countries ORDER BY name';
$rows = $db->fetchAll($sql);
$countries = $rows[0];

If you are in a class that extends Zend_Db_Table_Abstract, you may want to
think about a table select, though it would not be any less code then your
current fetchAll() solution.

-Mark

-----
Mark Garrett
DNA
Arkadelphia, AR
(Telecommuting to: Rogue River, OR)
--
View this message in context: http://www.nabble.com/fetchCol%28%29-not-returning-results-tp24069151p24081767.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: