From: s dot pfalz at teles dot de
Operating system: Linux
PHP version: 5.2.9
PHP Bug Type: OCI8 related
Bug description: oci_bind_by_name() binds non-existing variables
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??
--
Edit bug report at http://bugs.php.net/?id=48480&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=48480&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=48480&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=48480&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=48480&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=48480&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=48480&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=48480&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=48480&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=48480&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=48480&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=48480&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=48480&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=48480&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=48480&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48480&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48480&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=48480&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=48480&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=48480&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=48480&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=48480&r=mysqlcfg