WHERE条件中的变量

Hen*_*nri 1 php mysql sql where

PHP代码中的以下SQL查询不起作用,有人可以帮助我吗?

$reponse = $bdd->query("SELECT * FROM tasks WHERE destinataire = ':destinataire' ORDER BY maturity ASC");
$reponse->execute(array(
                ':destinataire'=>$_SESSION['login']
                ));
Run Code Online (Sandbox Code Playgroud)

正确的查询如下:

$reponse = $bdd->prepare("SELECT * FROM tasks WHERE destinataire = :destinataire ORDER BY maturity ASC");
Run Code Online (Sandbox Code Playgroud)

Joh*_*Woo 9

当你想参数化查询时,参数不应该用单引号包装,因为它们被转换为字符串文字(意味着它们只是常规值而不再是参数).删除单引号,它将起作用.

$reponse = $bdd->prepare("SELECT * FROM tasks WHERE destinataire = :destinataire ORDER BY maturity ASC");
Run Code Online (Sandbox Code Playgroud)

  • 你必须使用准备,而不是查询. (2认同)