From:
Operating system: Windows, Linux
PHP version: 5.3.8
Package: PDO related
Bug Type: Bug
Bug description:HAVING parameters cannot be bound in SQLite
Description:
------------
An SQL query in PDO and SQLite which has a bound parameter in the having
clause will return no result. If that parameter is inserted in the SQL
string, the query works fine.
There is no URL to watch the bug, so here's my code:
Test script:
---------------
--- SQL setup:
create table things (name);
insert into things values ('car');
insert into things values ('car');
insert into things values ('car');
insert into things values ('car');
insert into things values ('car');
insert into things values ('car');
insert into things values ('bus');
insert into things values ('bus');
insert into things values ('bus');
insert into things values ('bus');
insert into things values ('bus');
insert into things values ('train');
insert into things values ('train');
insert into things values ('train');
insert into things values ('train');
insert into things values ('train');
insert into things values ('airplane');
insert into things values ('tree');
insert into things values ('tree');
insert into things values ('chair');
insert into things values ('chair');
insert into things values ('chair');
--- PHP code:
<?php
$sql = 'select name, count(*) cnt
from things
group by name
having cnt >= ?
order by cnt desc';
$params = array(3);
$pdo = new PDO('sqlite:havingtest.db');
$ps = $pdo->prepare($sql);
$r = $ps->execute($params);
$records = $ps->fetchAll(PDO::FETCH_ASSOC);
header('Content-type: text/plain');
var_dump($records);
?>
Expected result:
----------------
array(4) {
[0]=>
array(2) {
["name"]=>
string(3) "car"
["cnt"]=>
string(1) "6"
}
[1]=>
array(2) {
["name"]=>
string(3) "bus"
["cnt"]=>
string(1) "5"
}
[2]=>
array(2) {
["name"]=>
string(5) "train"
["cnt"]=>
string(1) "5"
}
[3]=>
array(2) {
["name"]=>
string(5) "chair"
["cnt"]=>
string(1) "3"
}
}
Actual result:
--------------
array(0) {
}
--
Edit bug report at https://bugs.php.net/bug.php?id=60281&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=60281&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=60281&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=60281&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=60281&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=60281&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=60281&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=60281&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=60281&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=60281&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=60281&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=60281&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=60281&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=60281&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=60281&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=60281&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=60281&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=60281&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=60281&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=60281&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=60281&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=60281&r=mysqlcfg