php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54026 PostgreSQL: cannot bind NULL value to statement condition
Submitted: 2011-02-15 14:59 UTC Modified: 2013-10-15 11:54 UTC
From: abrahala at gmail dot com Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.3.5 OS: Debian GNU/Linux 2.6.26-2-amd64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
15 + 48 = ?
Subscribe to this entry?

 
 [2011-02-15 14:59 UTC] abrahala at gmail dot com
Description:
------------
It seems to be impossible to pass NULL value to a PDO PostgreSQL statement neither with bindValue nor using '?'-format and $statement->execute(array(null)).

Test script:
---------------
$pdo = new PDO('pgsql:host=localhost;port=5432;dbname=db', 'user', 'pass');
$statement = $pdo->prepare('SELECT \'ok\' WHERE NULL IS :nullValue');
$statement->bindValue(':nullValue', null, PDO::PARAM_NULL);
$statement->execute();
$result = $statement->fetchColumn(0);
var_export($result);

Expected result:
----------------
'ok'

Actual result:
--------------
false

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-15 15:28 UTC] abrahala at gmail dot com
-Summary: PostgreSQL: cannot bind NULL value to statement +Summary: PostgreSQL: cannot bind NULL value to statement condition
 [2011-02-15 15:28 UTC] abrahala at gmail dot com
Sorry, I forgot to mention this only applies to binding a null value as part of a condition. Value assignment works fine (fieldName = :nullValue), so it might has to do something with the 'IS' keryword?
 [2011-07-30 23:36 UTC] dverite at gmail dot com
You should write "...WHERE :nullValue IS NULL" instead of ".. WHERE NULL IS :nullValue", otherwise execute() fails with a syntax error.
I'm not sure your example would work anyway since passing a null value in a bind parameter seems problematic, but at least it would fail because of PDO and not because of the SQL itself :)
 [2013-06-28 20:16 UTC] yohgaki@php.net
-Status: Open +Status: Feedback
 [2013-06-28 20:16 UTC] yohgaki@php.net
Did last comment work for you?
 [2013-10-15 11:54 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 13 21:01:31 2024 UTC