php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69344 PDO PgSQL Incorrect binding numeric array with gaps
Submitted: 2015-04-01 10:33 UTC Modified: 2015-06-11 21:53 UTC
From: sergey dot nevmerzhitsky at gmail dot com Assigned: mbeccati (profile)
Status: Closed Package: PDO PgSQL
PHP Version: 5.4.39 OS: Ubuntu 14.04.2 3.13.0-48
Private report: No CVE-ID: None
 [2015-04-01 10:33 UTC] sergey dot nevmerzhitsky at gmail dot com
Description:
------------
If pass a numeric array with gaps in keys as argument of PDOStatement::execute(), DB returns not all matched rows.

Test script:
---------------
$needValues = [
    'aaa',
    'bbb',
    'ccc',
    'bbb', // Copy of key 1.
    'ddd'
];
$needValues = array_unique($needValues); // Produce array with keys gap
// $needValues = array_values(array_unique($needValues)); // No keys gap => NO BUG

$sql = 'SELECT "value" FROM "values_table" WHERE "value" IN (%s)';
$sql = sprintf($sql, implode(',', array_fill(0, count($needValues), '?')));
$stmt = $postgresDb->prepare($sql);
$stmt->execute($needValues);

var_dump($stmt->fetchAll());

Expected result:
----------------
"ddd"
"ccc"
"bbb"
"aaa"

Actual result:
--------------
"ccc"
"bbb"
"aaa"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-11 21:53 UTC] mbeccati@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: mbeccati
 [2015-06-11 21:53 UTC] mbeccati@php.net
This might require some discussion as fixing it would be a behaviour change.
 [2015-06-12 00:09 UTC] mbeccati@php.net
Automatic comment on behalf of mbeccati
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b60efdce9fe7e168ba37070a4307269483a66ea4
Log: Fix bug #69344 (PDO PgSQL Incorrect binding numeric array with gaps)
 [2015-06-12 00:09 UTC] mbeccati@php.net
-Status: Verified +Status: Closed
 [2015-06-23 18:04 UTC] ab@php.net
Automatic comment on behalf of mbeccati
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b60efdce9fe7e168ba37070a4307269483a66ea4
Log: Fix bug #69344 (PDO PgSQL Incorrect binding numeric array with gaps)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC