Edit report at https://bugs.php.net/bug.php?id=60281&edit=1
ID: 60281
User updated by: nospam at unclassified dot de
Reported by: nospam at unclassified dot de
Summary: HAVING parameters cannot be bound in SQLite
-Status: Open
+Status: Closed
Type: Bug
Package: PDO related
Operating System: Windows, Linux
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
Invalid bug. It's not about that parameters could not be bound, but SQLite
seems particularly picky about the parameter type in a HAVING clause (as
opposed to the WHERE clause), and PDO's stupid default PARAM_STR just doesn't
fit here. You cannot use the execute($parameters) method here but need to
bindParam(x, y, PDO::PARAM_INT/STR/...) every single parameter yourself. You
might as well quote those values and put them into the SQL string, that's
probably easier.
Previous Comments:
------------------------------------------------------------------------
[2011-11-12 15:59:11] nospam at unclassified dot de
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 this bug report at https://bugs.php.net/bug.php?id=60281&edit=1