【发布时间】:2016-03-19 14:35:34
【问题描述】:
我正在使用 PHO PDO 并让它返回一个关联数组。
我可以遍历 PDO 创建的关联数组,但我不知道如何从函数中返回数组。
function wantedrentals($provence, $country, $dbh)
{
echo "Now in wanted wanted rentals function<br><br>";
$journeyrentalssarray = array();
$sth = $dbh->query("SELECT summary, url, provence, country from tblAccomadation WHERE country = $country ");
# setting the fetch mode
$sth->setFetchMode(PDO::FETCH_ASSOC);
while($row = $sth->fetch())
{
echo $row['summary'] . "\n";
echo $row['url'] . "\n";
echo $row['provence'] . "\n";
echo $row['country'] . "\n";
}
return $journeyrentalssarray;
}
我对 PHP 和 PDO 非常陌生,希望能提供任何帮助。
【问题讨论】:
-
var_dump( $row );得到什么? -
你可能想看看这个:PDOStatement::fetchAll。此函数将整个结果作为数组返回。