php pdo show tables,php – 使用PDO回显显示表中的所有行

我试图用PDO回显表的所有行,但遇到了麻烦.

用旧的做法,我已经做到了

$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)){

$title= $row['title'];

$body= $row['body'];

}

但是我正在尝试使用PDO;

$result = $db->prepare("SELECT title, body FROM post");

$result->execute();

while ($row = $db->fetchAll(PDO::FETCH_ASSOC))

{

$title = $row['title'];

$body = $row['body'];

}

echo $title;

echo $body;

哪个一直给我调用未定义的方法PDO :: fetchAll()

做手册中给出的例子

$sth = $dbh->prepare("SELECT name, colour FROM fruit");

$sth->execute();

/* Fetch all of the remaining rows in the result set */

print("Fetch all of the remaining rows in the result set:\n");

$result = $sth->fetchAll();

print_r($result);

?>

工作,但我不认为我可以控制单个列,就像我用$row = [‘blah’];我呢?它也像这样打印出来;相当难看:

Array ( [0] => Array ( [title] => This is the test title entered in the database[0]

要正确使用PDO来做这件事需要做些什么?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值