From: php at richardneill dot org
Operating system: Linux
PHP version: 5.3.16
Package: PostgreSQL related
Bug Type: Bug
Bug description:pg_query_params() doesn't handle NULL
Description:
------------
pg_query_params($conn,$sql,$params) is supposed to correctly handle
NULL->SQL_NULL. It doesn't do this (despite the documentation); instead it
breaks the query.
Documentation
"If parameters are used, they are referred to in the query string as $1,
$2, etc. params specifies the actual values of the parameters. A NULL value
in this array means the corresponding parameter is SQL NULL. "
Test script:
---------------
Here's a simple example:
$result = pg_query_params ($conn,
"select CASE WHEN NULL is $1 then 'it is null' ELSE 'it is not null'
END",
array(NULL) );
echo pg_last_error($conn);
print_r (pg_fetch_assoc($result));
This query fails, because the parameter $1 is not actually passed as NULL,
instead it seems to be the empty string.
My SQL is definitely right:
pg_query_params ($conn,
"select CASE WHEN NULL is NULL then 'it is null' ELSE 'it is not null'
END",
array() );
works fine, to return the string "it is null".
Expected result:
----------------
It should be possible to pass SQL_NULL to the database in a parameter.
--
Edit bug report at https://bugs.php.net/bug.php?id=62998&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=62998&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=62998&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=62998&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=62998&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=62998&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=62998&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=62998&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=62998&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=62998&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=62998&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=62998&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=62998&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=62998&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=62998&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=62998&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62998&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=62998&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=62998&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=62998&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=62998&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=62998&r=mysqlcfg