php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72028 pg_query_params(): NULL converts to empty string
Submitted: 2016-04-15 09:25 UTC Modified: -
From: iivarih at gmail dot com Assigned:
Status: Closed Package: PostgreSQL related
PHP Version: 7.0.5 OS: Debian Jessie
Private report: No CVE-ID:
 [2016-04-15 09:25 UTC] iivarih at gmail dot com
Description:
------------
pg_query_params(): NULL converts to empty string, but only after looping over the params array with a reference.

php version: 7.0.5-1~dotdeb+8.1
tested against postgres 9.5

Test script:
---------------
$sql = "INSERT INTO params_test (value, details) VALUES ($1, $2)";

$params = array(null, "insert before looping with a reference");
$result = pg_query_params($this->connection, $sql, $params);

$params2 = array(null, "insert after looping with a reference");
foreach ($params2 as &$p) {
    // doing nothing
}
unset($p);
$result = pg_query_params($this->connection, $sql, $params2);


Expected result:
----------------
I would expect that both calls to pg_query_params() would insert SQL NULL as 'value'.

Actual result:
--------------
The first call to pg_query_params() inserts SQL NULL as expected:
  2016-04-15 11:59:07 EEST LOG:  execute <unnamed>: INSERT INTO params_test (value, details) VALUES ($1, $2)
  2016-04-15 11:59:07 EEST DETAIL:  parameters: $1 = NULL, $2 = 'insert before looping with a reference'

The second call inserts empty string as 'value' which is unexpected:
  2016-04-15 11:59:07 EEST LOG:  execute <unnamed>: INSERT INTO params_test (value, details) VALUES ($1, $2)
  2016-04-15 11:59:07 EEST DETAIL:  parameters: $1 = '', $2 = 'insert after looping with a reference'


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-16 04:30 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7e01c518b6a504846f397b787ab285105531d562
Log: Fixed bug #72028 (pg_query_params(): NULL converts to empty string)
 [2016-04-16 04:30 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-04-16 04:30 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7e01c518b6a504846f397b787ab285105531d562
Log: Fixed bug #72028 (pg_query_params(): NULL converts to empty string)
 [2016-07-15 09:01 UTC] ravisen at mail dot ru
The problem has not been solved so far. Repeats on the version of PHP Version 7.0.8-4
 [2016-07-20 11:32 UTC] davey@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7e01c518b6a504846f397b787ab285105531d562
Log: Fixed bug #72028 (pg_query_params(): NULL converts to empty string)
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Apr 30 18:01:35 2017 UTC