带有预准备语句的 PDO bindParam() 不起作用
好的,这就是问题所在:
这有效:
$STH = $DBH->prepare("SELECT * FROM juegos WHERE id = 1");
$STH->execute();
这不会:
$STH = $DBH->prepare("SELECT * FROM juegos WHERE id = :id");
$STH->bindParam(':id', '1', PDO::PARAM_STR);
$STH->execute();
我到底做错了什么?它甚至不会引发异常
谢谢大家!
另外,这是整个代码
<?php
try {
$DBH = new PDO("everything is", "ok", "here");
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$STH = $DBH->prepare("SELECT * FROM juegos WHERE id = :id");
$STH->bindParam(':id', '1', PDO::PARAM_STR);
$STH->execute();
$STH->setFetchMode(PDO::FETCH_ASSOC);
while($row = $STH->fetch()) {
echo $row['nombre']."<br/>";
}
$DBH = null;
echo "Todo salió bien";
} catch (PDOException $e) {
echo "Error";
}
?>