|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-02-20 23:25 UTC] tyler at sleekcode dot net
Description:
------------
Passing NULL via pg_query_params does not work resulting in situations where a possible NULL value must have a secondary branch of code to adjust the query accordingly.
Reproduce code:
---------------
using postgres 8x create this test table:
CREATE TABLE test
(
id serial PRIMARY KEY,
name text,
extra text,
);
INSERT INTO test (name,extra) VALUES ('Testing 123,'Testing');
INSERT INTO test (name) VALUES ('My extra is null');
<?php
$db = pg_connect("your connection string");
// set postgresql to allow = NULL instead of requiring IS NULL
pg_query("set transform_null_equals to on");
// query for all records where extra = NULL (postgres converts to extra IS NULL)
$res = pg_query_params("SELECT name FROM test WHERE extra=$1",array(NULL));
// print result, should be 'My extra is null'
print pg_fetch_result($res,0);
?>
Expected result:
----------------
The code should return the first result that matches the query.
Actual result:
--------------
The query does not run correctly.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 08:00:02 2025 UTC |
Additionally, the correct syntax: pg_query_params("SELECT name FROM test WHERE extra IS $1",array(null)); ...fails as well.It's pity that it was marked as not a bug. It really makes me ill to constantly write: if ($column_value === null) } $where[] = "column is null"; } else { $where[] = "column = :column_value"; $parameters['column_value'] = $column_value; } instead of just: $where[] = "column = :column_value"; $parameters['column_value'] = $column_value; IMHO, if someone decides to enable transform_null_equals on his PostgreSQL database then PDO should respect that decision.