php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34607 oci_bind_by_name fails when $variable has NULL value
Submitted: 2005-09-23 05:44 UTC Modified: 2005-10-01 01:00 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: robcolbert at yahoo dot com Assigned:
Status: No Feedback Package: OCI8 related
PHP Version: 5.0.5 OS: Fedora Core 4
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: robcolbert at yahoo dot com
New email:
PHP Version: OS:

 

 [2005-09-23 05:44 UTC] robcolbert at yahoo dot com
Description:
------------
It is not possible to use oci_bind_by_name to assign a NULL value to a placeholder. The OCI will attempt to allocate a very large (negative) amount of memory and cause the script to exit due to memory depletion.

I'm not sure if this is a bug or intended behavior, but it was frustrating to figure out, and limits the programmer's ability to use a truly generic statement for all cases. I have found myself having to code constructs such as:

if( $SomeVarB == NULL )
{
    $SQL = "INSERT INTO table (a, b) VALUES (:a, NULL)";
    $stid = $oci_parse($conn, $SQL);
    oci_bind_by_name($stid, ":a", $SomeVarA);
}
else
{
    $SQL = "INSERT INTO table (a, b) VALUES (:a, :b)";
    $stid = $oci_parse($conn, $SQL);
    oci_bind_by_name($stid, ":a", $SomeVarA);
    oci_bind_by_name($stid, ":b", $SomeVarB);
}

This is bloating scripts unnecessarily, and I expect that other programmers are experiencing similar results. It would be better if NULL could be specified as the input variable value to mean that the OCI should use NULL for the given placeholder's value such as:

$SomeVarB = NULL;
oci_bind_by_name($stid, ":b", $SomeVarB);

Reproduce code:
---------------
$SomeVarB = NULL;
oci_bind_by_name($stid, ":placeholder", $SomeVarB);

Expected result:
----------------
The OCI should use the NULL SQL value supplied as the value of the $variable input parameter. The OCI should attempt to allocate an enormous amount of memory and cause the script to terminate.

If NULL cannot be handled as an input $variable value, then it is expected for the API to return an error code and allow the application to handle the error rather than causing an abortive condition (script termination) to occur.

Actual result:
--------------
PHP Fatal error:  Allowed memory size of 8388608 bytes exhausted (tried to allocate -153092209 bytes).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-23 08:00 UTC] cjbj at hotmail dot com
I was just about to log a similar bug.  Here is my testcase:
<?php

/*

    With new oci8 driver output is

        Notice: Undefined variable: undef2 in testcase.php on line 35

        Fatal error: Allowed memory size of 8388608 bytes exhausted
        (tried to allocate -153092209 bytes) in testcase.php on line
        37

    With old oci8 extension, output is

        Notice: Undefined variable: undef2 in testcase.php on line 35

        array(1) {
          ["DUMMY"]=>
          array(0) {
          }
        }

*/

define('ORA_CON_UN', 'hr');
define('ORA_CON_PW', 'hr');
define('ORA_CON_DB', '//localhost/orcl');

$statement = "select * from dual where dummy = :mybv";

$conn = oci_connect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);

$stid = oci_parse($conn, $statement);

$r = oci_bind_by_name($stid, ":mybv", $undef, $undef2);

$r = oci_execute($stid, OCI_DEFAULT);

$r = oci_fetch_all($stid, $results);

echo "<pre>"; var_dump($results); echo "</pre>";
?>
 [2005-09-23 09:02 UTC] tony2001@php.net
It's fixed 2 weeks ago.
Please try OCI v.1.1.1 from PECL.
 [2005-10-01 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 00:01:41 2024 UTC