【发布时间】:2015-08-09 11:27:02
【问题描述】:
我正在尝试创建一个聊天室作为练习,我的代码有一个奇怪的行为: (PS:使用 wampserver 运行)
<?php
header('Content-Type: application/x-www-form-urlencoded');
try{
$pdo_options[PDO::ATTR_ERRMODE]=PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=test','root','',$pdo_options);
$msg = $bdd -> query('SELECT * FROM chatroom ORDER BY heure LIMIT 0,10');
while($current = $msg->fetch()){
?>
<div class='messages' ><?php echo $current['id']; ?></div><br/>
<?php
}
$msg->closeCursor();
}
catch(Exception $e){
die('Erreur:'.$e->getMessage());
}
?>
我明白了:
query('SELECT * FROM chatroom ORDER BY heure LIMIT 0,10'); while($current = $msg->fetch()){ ?>
closeCursor(); } catch(Exception $e){ die('Erreur:'.$e->getMessage()); } ?>
我哪里错了?一定是某个地方有语法错误,但我没找到。
【问题讨论】: