2009年6月17日星期三

[fw-db] fetchCol() not returning results

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');
...
?>

This outputs:

$rows array(0) {
}


My work around is to use fetchAll() in the following way:

<?php
...
$db = $this->getAdapter(); // MYSQLI
$sql = 'SELECT name FROM countries ORDER BY name';
$rows = $db->fetchAll($sql);
$array = array();
foreach ($rows as $row)
{
$array[] = $row['name'];
}
$rows = $array;
Zend_Debug::dump($rows, '$rows');
...
?>

Which the correctly outputs:

$rows array(80) {
[0] => string(9) "Argentina"
[1] => string(9) "Australia"
[2] => string(7) "Austria"
[3] => string(7) "Belgium"
...
}


Any one spot what I'm doing wrong with fetchCol()?

Regards,

Ian


--
View this message in context: http://www.nabble.com/fetchCol%28%29-not-returning-results-tp24069151p24069151.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: