[英]PDO mysql select query not executing
Why is this PDO not executing?为什么这个 PDO 没有执行?
$statement = $db->prepare("select * from quest where id = :'"+$testno+"'");
$statement->execute();
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo "Q:".$row["questions"];
The "Q" is not echoed. “Q”没有回显。
You should put named placeholder in prepared sql and bind it to desired value later:您应该将命名占位符放在准备好的 sql 中,然后将其绑定到所需的值:
$statement = $db->prepare("select * from quest where id = :id");
$statement->bindParam(':id', $testno, \PDO::PARAM_INT);
$statement->execute();
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo "Q:".$row["questions"];
Assuming id is integer, if not - replace \\PDO::PARAM_INT
with \\PDO::PARAM_STR
.假设 id 是整数,如果不是 - 用
\\PDO::PARAM_INT
替换\\PDO::PARAM_STR
。
$statement = $db->prepare("select * from quest where id = :testno");
$statement->execute(array(':testno'=>$testno));
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo "Q:".$row["questions"];
@X10nD, Simply use like below code... :) @X10nD,只需像下面的代码一样使用... :)
$query = "SELECT * FROM quest WHERE id = ?";
$statement = $db->prepare($query);
$statement->bindParam(1,$testno);
$statement->execute();
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo "Q:".$row['questions'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.