php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36812 bind NULL variables generates warning
Submitted: 2006-03-21 12:38 UTC Modified: 2006-11-13 22:11 UTC
From: ce at netage dot bg Assigned:
Status: Closed Package: PostgreSQL related
PHP Version: 5.1.3RC1 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ce at netage dot bg
New email:
PHP Version: OS:

 

 [2006-03-21 12:38 UTC] ce at netage dot bg
Description:
------------
when binding explicit null value there is no problem (see the workarround), but, when the null value is from variable there is a problem (the example is stupid, but is the simplest one representing the problem)

Reproduce code:
---------------
CREATE TABLE nullproblem (i integer);

<?
$conn = pg_connect('dbname=test');

$temp1 = null;

$param_list = array($temp1, $temp1, $temp1, );

/*******************
 workarround:

$param_list = array(is_null($temp1)?null:$temp1, is_null($temp1)?null:$temp1, is_null($temp1)?null:$temp1, );

****************/

pg_prepare($conn, 'test', 'INSERT INTO nullproblem VALUES (case when $2::int IS NULL then $3::int else $1::int end)');
pg_execute($conn, 'test', $param_list);
?>

Expected result:
----------------
nothing special

Actual result:
--------------
Warning: pg_execute(): Query failed: ERROR:  invalid input syntax for integer: "" in test.php on line 10

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-22 18:19 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You declare the parameter is being of type INT and then put NULL into it. Is it any wonder PostgreSQL generates an error?
 [2006-03-23 09:58 UTC] ce at netage dot bg
check the workarround and see how an array of 

$param_list = array(null, null, null);

does NOT generate any error, actually working as expected (so the problem is not at the integer type of the column, because it has the right to be NULL)
 [2006-09-26 22:30 UTC] tony2001@php.net
Assigned to the maintainer.
 [2006-11-11 14:16 UTC] dave@php.net
This happens because pg_execute() modifies the array values, so $temp1 gets passed a NULL initially, then $temp1 is converted to a string which is why the second time it is passed it fails to execute.

This can be demonstrated by doing var_dump($temp1); before and after the pg_execute() statement.

I don't claim to know PHP internals, but perhaps the fact that it uses convert_to_string() instead of convert_to_string_ex() is the cause?
 [2006-11-13 22:11 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC