【发布时间】:2012-08-28 12:11:30
【问题描述】:
如何使用 PHP PDO 多次返回对象?
根据我下面的代码,$result 对象在 while 循环中不显示任何数据。
我的代码
try {
$dbhandle = new PDO("sqlite:".$database);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$result=$dbhandle->query("select * from table");
if($result)
{
$row=$result->fetch(PDO::FETCH_ASSOC)
if(count($row)>0)
{
while ($rs1 = $result->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))
{
echo "<pre>";
print_r($rs1);
echo "</pre>";
}
}
else
{
// error message
}
}
【问题讨论】: