php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48480 oci_bind_by_name() binds non-existing variables
Submitted: 2009-06-05 11:36 UTC Modified: 2021-03-04 12:15 UTC
Votes:4
Avg. Score:3.0 ± 1.4
Reproduced:2 of 3 (66.7%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: s dot pfalz at teles dot de Assigned: cmb (profile)
Status: Closed Package: OCI8 related
PHP Version: 5.2.9 OS: Linux
Private report: No CVE-ID: None
 [2009-06-05 11:36 UTC] s dot pfalz at teles dot de
Description:
------------
When using oci_bind_by_name() to add data feed by an associative array, this function adds non-existant data! 
In the example code the function getDataArray() contains an associative array with a master key called A,B and C. 
A and B arrays are complete, however for master key C the sub-fields "f1" and "f2" are missing.
The code simply loops through the array, binds the values and execute the query. Normally I would expect to run both A and B queries without any problem, however for the C query I would expect that OCI8 lib complains about not all variables bound. See expected/actual result what happened.

Reproduce code:
---------------
// Requires table: CREATE TABLE TESTOCI(NAME VARCHAR2(10),f1 VARCHAR2(80), f2 VARCHAR2(80));
function getDataArray($which)
  {
  $data['A']['name']  = 'NAME_A';
  $data['A']['f1']    = 'A_VAL_F1';
  $data['A']['f2']    = 'A_VAL_F2';
  $data['B']['name']  = 'NAME_B';
  $data['B']['f1']    = 'B_VAL_F1';
  $data['B']['f2']    = 'B_VAL_F2';
  $data['C']['name']  = 'NAME_C';
  return($data[$which]);
  }

ini_set('error_reporting', E_ALL|E_NOTICE);
$sock = OCILogon('scott','tiger');
$stmt = OCIParse($sock,'INSERT INTO TESTOCI(NAME,F1,F2) VALUES(:name,:f1,:f2)');
$tdat = array('A','B','C');
for($i =0 ; $i < count($tdat); $i++)
  {
  $what = array();
  printf("HANDLING SET=%s\n",$tdat[$i]);
  $what = getDataArray($tdat[$i]);
  print_r($what);
  foreach($what AS $n => $v)
    {
    printf("Calling OCIBindByName(\$stmt,'%s','%s',-1)\n",$n,$what[$n]);
    $rc = OCIBindByName($stmt,$n,$what[$n],-1);
    printf("OCIBindByName() returned %s\n",$rc);
    }
  print_r($what);
  OCIExecute($stmt,OCI_DEFAULT);
  unset($what);
  }
OCIFreeStatement($stmt);
OCICOMMIT($sock);
OCILogoff($sock);



Expected result:
----------------
I would expect that for the data array 'C' an error message should occure stating that not all variables are bound (f1,f2). So the contents of the table should be empty because the code should abort, and COMMIT_ON_SUCCESS is not set.



Actual result:
--------------
After running the code, the table contents look like this:

SQL> SELECT NAME,F1,F2 FROM TESTOCI;

NAME    F1              F2
--------------------------------
NAME_A  A_VAL_F1	A_VAL_F2
NAME_B  B_VAL_F1        B_VAL_F2
NAME_C  B_VAL_F1        B_VAL_F2

I really wonder how it is possible that the 3rd line contains the values of the previous call??

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-12 21:00 UTC] sixd@php.net
-Assigned To: +Assigned To: sixd
 [2017-10-24 07:52 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: sixd +Assigned To:
 [2019-01-03 22:13 UTC] camporter1 at gmail dot com
This does not appear to be a bug. The B f1 and f2 values are still bound when performing the C iteration since the C iteration does not rebind f1 and f2, because $what does not contain them.
 [2021-03-04 12:15 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-03-04 12:15 UTC] cmb@php.net
Indeed, like camporter1 said.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC