Reputation: 22030
Why is this PDO not executing?
$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.
Upvotes: 0
Views: 238
Reputation: 19278
You should put named placeholder in prepared sql and bind it to desired value later:
$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
.
Upvotes: 4
Reputation: 2526
@X10nD, Simply use like below code... :)
$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'];
Upvotes: 0
Reputation: 3097
$statement = $db->prepare("select * from quest where id = :testno");
$statement->execute(array(':testno'=>$testno));
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo "Q:".$row["questions"];
Upvotes: 1