I'm trying to use prepared statements in a PHP script that accesses an SQLite3 database using PDO.
The normal version of this query works as expected:
$q1 = "SELECT COUNT(*) FROM fruits WHERE name='apple'";
echo $db->query($q1)->fetchColumn();
However, my prepared statement version outputs nothing.
$q2 = "SELECT COUNT(*) FROM fruits WHERE name='?'";
$s = $db->prepare($q2);
$s->execute("apple");
echo $s->fetchColumn();
What am I doing wrong? I tried with both PHP 5.2 and PHP 5.3, with the same results.