帮助对 PDO 准备好的语句进行故障排除
我刚刚开始学习 PDO 和准备好的语句(这似乎比每次记住使用 mysql_real_escape_string() 都要好),但我在让脚本正确执行时遇到了麻烦:
<?php
error_reporting(E_ALL);
echo "start";
try{
$dbh=new PDO('mysql:host=localhost;dbname=DBNAME','USER','PWD');
}
catch(PDOException $e){
echo 'Error connecting to MySQL!: '.$e->getMessage();
exit();
}
$dbh->prepare('SELECT * FROM users WHERE uid= ?');
$dbh->execute(array('15400743'));
$result=$dbh->fetchAll();
print_r($result);
echo "end";
?>
这几乎是从示例代码中复制的,但是当执行仅返回“开始”。我已经仔细检查了我的 db/user/pw。人们还有什么看错的地方吗?谢谢!
I've just started learning aboud PDO and prepared statements (which sure seem to beat remembering to use mysql_real_escape_string() every time) but I'm having trouble getting the script to execute properly:
<?php
error_reporting(E_ALL);
echo "start";
try{
$dbh=new PDO('mysql:host=localhost;dbname=DBNAME','USER','PWD');
}
catch(PDOException $e){
echo 'Error connecting to MySQL!: '.$e->getMessage();
exit();
}
$dbh->prepare('SELECT * FROM users WHERE uid= ?');
$dbh->execute(array('15400743'));
$result=$dbh->fetchAll();
print_r($result);
echo "end";
?>
This is pretty much copied from example code, but when executed only returns "start". I've double-checked my db/user/pw. Anything else people see wrong? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的方法是:
注意prepare对$stmt变量的分配以及之后的使用。
The correct way is:
Note the assinment of the prepare to the $stmt variable and the use of that afterwards.