From: cjbj at hotmail dot com
Operating system:
PHP version: 4CVS-2004-02-18 (stable)
PHP Bug Type: OCI8 related
Bug description: OCIBindByName binds numeric PHP values as characters
Description:
------------
Numeric PHP variables seem to be treated as strings when bound with
OCIBindByName. The means the desired number of significant digits
needs to be specified in the OCIBindByName call. Othewise only the
most significant digit is returned.
PHP scripts could be simpler and safer to write if:
(i) a pre-existing numeric PHP variable automatically caused a
SQLT_INT bind
(ii) OCI's SQLT_INT type could be specified in the OCIBindByName
call, with a new OCI_B_xxx define
For example, try a RETURNING INTO clause with a sequence value:
<?php
/*
Execute these in SQL*Plus prior to running this PHP script:
drop sequence myseq;
drop table mytab;
create sequence myseq;
create table mytab (mydata varchar2(20), seqcol number);
*/
define('MYLIMIT', 200);
define('INITMYBV', 11);
$conn = OCILogon("scott", "tiger", "mydb");
$stmt = "insert into mytab (mydata, seqcol) values ('Some data',
myseq.nextval) returning seqcol into :mybv";
$stid = OCIParse($conn, $stmt);
if (!$stid) { echo "Parse error"; die; }
//$mybv = INITMYBV; // Uncomment this for the 2nd test only
$r = OCIBindByName($stid, ':MYBV', $mybv /*, 5 */); // Uncomment this
for the 3rd test only
if (!$r) { echo "Bind error"; die; }
for ($i = 1; $i < MYLIMIT; $i++) {
$r = OCIExecute($stid, OCI_DEFAULT);
if (!$r) { echo "Execute error"; die; }
echo "Bind variable is $mybv<br>\n";
}
OCICommit($conn);
?>
The output is:
Bind variable is 1
Bind variable is 2
Bind variable is 3
Bind variable is 4
Bind variable is 5
Bind variable is 6
Bind variable is 7
Bind variable is 8
Bind variable is 9
Bind variable is 1
...
[This continues with 10 rows of 1's, then 10 rows of 2's etc. as
if the least significant digit(s) are being stripped.]
Querying the table in a SQL*Plus sessions shows the inserts are
occuring correctly and the sequence number is increasing past nine:
MYDATA SEQCOL
-------------------- ----------
Some data 1
Some data 2
Some data 3
Some data 4
Some data 5
Some data 6
Some data 7
Some data 8
Some data 9
Some data 10
...
Some data 199
Expected result
Bind variable is 1
Bind variable is 2
Bind variable is 3
Bind variable is 4
Bind variable is 5
Bind variable is 6
Bind variable is 7
Bind variable is 8
Bind variable is 9
Bind variable is 10
...
Bind variable is 199
Testcase 2 is to set $mybv to a value before the OCIBindByName by
uncommenting the line marked 2nd test. The value set is bound as a
string. The number of digits in it will determine the maximum width
of the returned bind result. For example if $mybv is set to 11, then
all two-digit values are displayed correctly.
Testcase 3 is to pass a width to OCIBindByName. Uncomment the text
marked 3rd test. This works until the number of digits in the
sequence number is greater than the passed width.
Another different testcase might be calling a PL/SQL procedure with a
IN/OUT parameter. Although the passed value is correct, the out value
may not be.
If the current behavior is deemed desired, can this bug be made a
documentation bug? Users may be easily tricked because there is no
mention of the default bind type being character, and the
OCIBindByName documentation "and the necessary storage space will be
allocated" could be thought to apply to PHP numeric variables.
--
Edit bug report at http://bugs.php.net/?id=27303&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27303&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27303&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27303&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27303&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27303&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27303&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27303&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27303&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27303&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27303&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27303&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27303&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27303&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27303&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27303&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27303&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27303&r=float