php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70302 Parameter bind with OCI8 is broken - always last parameter value bound to all
Submitted: 2015-08-19 12:33 UTC Modified: 2015-09-20 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: deepdiver at owncloud dot com Assigned: sixd (profile)
Status: No Feedback Package: OCI8 related
PHP Version: 7.0.0beta3 OS: Linux
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:
46 - 31 = ?
Subscribe to this entry?

 
 [2015-08-19 12:33 UTC] deepdiver at owncloud dot com
Description:
------------
Query parameters are always bound to the value of the last parameter.

See the test script below.

Here is the out come with php 5.6:
$ php test.php 
XDebug could not open the remote debug file '/tmp/xdebug.log'.
array(1) {
  [0] =>
  array(3) {
    'A' =>
    string(1) "1"
    'B' =>
    string(1) "2"
    'C' =>
    string(1) "3"
  }
}

With 7.0.0beta3:

$ php --version
PHP 7.0.0beta3 (cli) (built: Aug 17 2015 17:19:56) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
deepdiver@alien:~/Development/ownCloud/php7-mysql$ php test.php 
array(1) {
  [0]=>
  array(3) {
    ["A"]=>
    string(1) "3"
    ["B"]=>
    string(1) "3"
    ["C"]=>
    string(1) "3"
  }
}

Test script:
---------------
<?php
require 'vendor/autoload.php';

$config = new \Doctrine\DBAL\Configuration();
//..
$connectionParams = array(
        'dbname' => 'XE',
        'user' => 'autotest',
        'password' => 'owncloud',
    'host' => '10.0.0.7',
    'port' => 1521,
        'driver' => 'oci8',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);

$conn->connect();

$conn->executeUpdate('DROP TABLE TEST');
$conn->executeUpdate('CREATE TABLE TEST(A VARCHAR2(4000) NOT NULL, B VARCHAR2(4000) NOT NULL, C VARCHAR2(4000) NOT NULL)');

$conn->insert('TEST', [
    'A' => '1',
    'B' => '2',
    'C' => '3']);

$all = $conn->fetchAll('select * from TEST');
var_dump($all);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-20 04:07 UTC] sixd@php.net
-Status: Open +Status: Feedback
 [2015-08-20 04:07 UTC] sixd@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

Your subject says "OCI", the category says "PDO_OCI" but the sample code indicates you might mean OCI8.

Can you clarify and also supply a runnable testcase that doesn't depend on any 3rd party code?

If this is OCI8, is the problem related to one of the known diffs?  Try running the test suite.
 [2015-08-20 08:55 UTC] deepdiver at owncloud dot com
-Status: Feedback +Status: Open -Package: PDO OCI +Package: OCI8 related
 [2015-08-20 08:55 UTC] deepdiver at owncloud dot com
Here is a pure OCI based script - which works \o/ - maybe a doctrine error then ....

<?php

function e($e) {
    if (!$e) {
        $e = oci_error();
        var_dump($e);
        exit;
    }
}

$conn = oci_connect('autotest', 'owncloud', '172.17.0.1/XE');
e($conn);

// drop table
$stid = oci_parse($conn, 'DROP TABLE TEST');
e($stid);
$r = oci_execute($stid);
e($r);

// create
$stid = oci_parse($conn, 'CREATE TABLE TEST(A VARCHAR2(4000) NOT NULL, B VARCHAR2(4000) NOT NULL, C VARCHAR2(4000) NOT NULL)');
e($stid);
$r = oci_execute($stid);
e($r);

// insert
$stid = oci_parse($conn, 'INSERT INTO TEST (A, B, C) VALUES(:a, :b, :c)');
e($stid);
$a = 1;
$b = 2;
$c = 3;
oci_bind_by_name($stid, ':a', $a);
oci_bind_by_name($stid, ':b', $b);
oci_bind_by_name($stid, ':c', $c);
$r = oci_execute($stid);  // executes and commits
e($r);

// select
$stid = oci_parse($conn, 'SELECT * FROM TEST');
e($stid);
$r = oci_execute($stid);  // executes and commits
e($r);
$data = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);
var_dump($data);
 [2015-08-23 23:08 UTC] sixd@php.net
-Summary: Parameter bind with OCI is broken - always last parameter value bound to all +Summary: Parameter bind with OCI8 is broken - always last parameter value bound to all -Status: Open +Status: Feedback -Assigned To: +Assigned To: sixd
 [2015-08-23 23:08 UTC] sixd@php.net
Your non-failing, pure OCI8 testscript didn't use an array for A,B,C unlike the earlier code.  Try changing the OCI8 test to be closer to the original.  And then review the test suites diffs to see if the problem is related to one of the known test failures.
 [2015-08-24 07:52 UTC] sixd@php.net
You logged this with 7.0.0beta3.  Can you test with master?  The most recent OCI8 fixes did not get into Beta3.
 [2015-08-24 20:43 UTC] deepdiver at owncloud dot com
Results are the same with master as of just now.
 [2015-09-06 04:22 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.
 [2015-09-06 04:48 UTC] requinix@php.net
-Status: No Feedback +Status: Open
 [2015-09-07 01:12 UTC] sixd@php.net
-Status: Assigned +Status: Feedback
 [2015-09-07 01:12 UTC] sixd@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2015-09-07 01:13 UTC] sixd@php.net
See my comment on [2015-08-23 23:08 UTC]
 [2015-09-20 04:22 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.
 [2016-07-19 06:44 UTC] mohammad at zeineddin dot name
I think this issue is known, and explained in details in the documentation in http://php.net/manual/en/function.oci-bind-by-name.php in "Example #3 Binding with a foreach() loop", if you can see a comments says "oci_bind_by_name($stid, $key, $val) does not work because it binds each placeholder to the same location: $val instead use the actual location of the data: $ba[$key]", so if you bind by name the same variable name, it will only use the last variable value, which is somehow wrong, it should take a copy of the variable value, and use it, not the last value of the variable!
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 19:01:51 2019 UTC