$STH->bindValue(':id', '1', PDO::PARAM_STR);Ok, this is the problem:This works:$STH = $DBH->prepare("SELECT * FROM juegos WHERE id = 1");$STH->execute();This doesn't:$STH = $DBH->prepare("SELECT * FROM juegos WHERE id = :id");$STH->bindParam(':id', '1', PDO::PARAM_STR);$STH->execute();What in the world am I doing wrong? It doesn't even throw an exceptionThank you everyone!Also, this is the whole code<?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"; }?> 解决方案 Using bindParam() the variable is bound as a reference.A string can't be passed by reference.The following things can be passed by reference:Try using bindValue()$STH->bindValue(':id', '1', PDO::PARAM_STR); 这篇关于带有准备好的语句的 PDO bindParam() 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-29 18:00