Odd PDO/SQLite3 bug

Okay, so consider PHP code like this:

$dbh = new PDO("sqlite::memory:");

$dbh->exec("
create table test(sid integer, str text);
insert into test values(1, 'hello there');
");

$sth = $dbh->prepare("select * from test where sid = ?");
$sth->execute(array(1));
print_r($sth->fetchAll());

Run this, and you get the expected result:

Array
(
[0] => Array
(
[sid] => 1
[0] => 1
[str] => hello there
[1] => hello there
)

)

However, if you remove the integer, or replace it with primary key (but not with integer primary key, mind you!), the query selects 0 rows. Oops. That’s not supposed to happen!

Also, it works with the sqlite2 PDO adapter. Strange, very strange.

Advertisements