以下PHP代码中的SQL查询不起作用,有人能帮我吗?
$reponse = $bdd->query("SELECT * FROM tasks WHERE destinataire = ':destinataire' ORDER BY maturity ASC");
$reponse->execute(array(
':destinataire'=>$_SESSION['login']
));
正确的查询如下:
$reponse = $bdd->prepare("SELECT * FROM tasks WHERE destinataire = :destinataire ORDER BY maturity ASC");
最佳答案
当您想要参数化查询时,参数不应该用单引号包装,因为它们被转换为字符串文字(这意味着它们只是常规值,不再是参数)。去掉单引号就行了。
$reponse = $bdd->prepare("SELECT * FROM tasks WHERE destinataire = :destinataire ORDER BY maturity ASC");