1

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");
4

1 回答 1

9

当您想对查询进行参数化时,不应将参数用单引号括起来,因为它们将转换为字符串文字这意味着它们只是常规值,不再是参数)。删除单引号,它将起作用。

$reponse = $bdd->prepare("SELECT * FROM tasks WHERE destinataire = :destinataire ORDER BY maturity ASC");
于 2013-03-06T17:24:20.420 回答