note 105911 modified in function.oci-bind-by-name by danbrown
| From: | danbrown@php.net | Date: | Mon, 26 Sep 2011 14:57:59 +0000 |
| Subject: | note 105911 modified in function.oci-bind-by-name by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183448@lists.php.net to get a copy of this message | ||
I unfortunately spent the whole day trying to make this work as part of OCI bind_by_name insert:
<?php
if(is_numeric($v2)){
oci_bind_by_name($stmth, $bvar, $v2, -1, OCI_B_INT);
}else{
$v2 = (string) $v2;
oci_bind_by_name($stmth, $bvar, $v2, -1, SQLT_CHR);
}
?>
The string field is always inserting correctly w/o any truncation. The string field is a
varchar2(160) CHAR, but the data used to populate it is 40 chars in length.
The numeric part is of Type Number in the database which is being used to store unix time (10 digit
seconds since 1970/01/01.
The problem, the insert was truncating to 9 digits with some bogus value not even related to the
input i.e., it's not just a matter of dropping the leftmost or rightmost digit, it'll just
insert a 9 digit bogus number.
The only way I was able to resolve this for the numeric field was to set the maxlength to 8 (not 10
which is the number of digits in the input):
<?php
if(is_numeric($v2)){
oci_bind_by_name($stmth, $bvar, $v2, 8, OCI_B_INT);
}else{
$v2 = (string) $v2;
oci_bind_by_name($stmth, $bvar, $v2, -1, SQLT_CHR);
}
?>
Hopefully you'll see this soon before you expend a lot of time repeating the same problem I
had.
--was--
I unfortunately spent the whole day trying to make this work as part of OCI bind_by_name insert:
if(is_numeric($v2)){
oci_bind_by_name($stmth, $bvar, $v2, -1, OCI_B_INT);
}else{
$v2 = (string) $v2;
oci_bind_by_name($stmth, $bvar, $v2, -1, SQLT_CHR);
}
The string field is always inserting correctly w/o any truncation. The string field is a
varchar2(160) CHAR, but the data used to populate it is 40 chars in length.
The numeric part is of Type Number in the database which is being used to store unix time (10 digit
seconds since 1970/01/01.
The problem, the insert was truncating to 9 digits with some bogus value not even related to the
input i.e., it's not just a matter of dropping the leftmost or rightmost digit, it'll just
insert a 9 digit bogus number.
The only way I was able to resolve this for the numeric field was to set the maxlength to 8 (not 10
which is the number of digits in the input):
if(is_numeric($v2)){
oci_bind_by_name($stmth, $bvar, $v2, 8, OCI_B_INT);
}else{
$v2 = (string) $v2;
oci_bind_by_name($stmth, $bvar, $v2, -1, SQLT_CHR);
}
Hopefully you'll see this soon before you expend a lot of time repeating the same problem I
had.
http://php.net/manual/en/function.oci-bind-by-name.php