Php oci_bind_by_name float to numeric

I need to associate a floating point number with an OCI instruction.

What am I doing:

$price = 0.1 oci_bind_by_name($resource, 'price', $price); 

In my Oracle database, “price” is the argument to the stored procedure, and the type is NUMERIC.

After completing my statement, I get the following error:

Message: oci_execute () [function.oci-execute]: ORA-06502: PL / SQL: numeric or value error: error converting number to number ORA-06512: on line 1

If $ price is an integer, everything works fine. In PHP docs http://lv.php.net/manual/en/function.oci-bind-by-name.php I did not find a special type for float for the fifth parameter (int $ type = SQLT_CHR).

Found answer: I just changed the decimal character in my OS from "," to ".". and now everything is working fine

+4
source share
2 answers

If you cannot change the decimal character of your OS (or simply do not want to), the only solution to this problem is to abandon the float parameters. You must enter the value directly in sql. You should also know how to use en_US as a locale for the correct delimited delimiter.

 // Ensure that the period is used as decimal separator when converting float to string setlocale(LC_ALL, 'en_US'); // Generate SQL // ... $variables = array(); if(is_int($myValue)) { $sql .= ':MYVALUE'; $variables[':MYVALUE'] = $myValue; } else if(is_float($myValue)) { $sql .= (string) $myValue; } // ... // Generate statement // $resource = oci_parse(...); // Bind parameters (if neccessary) if(count($variables) > 0) { foreach($variables as $name => &$variable) oci_bind_by_name($resource, $name, $variable); } 
0
source

Try: oci_bind_by_name($resource, 'price', $price, -1, SQLT_NUM); SQLT_NUM is simply missing from the documentation.

-1
source

Source: https://habr.com/ru/post/1390986/


All Articles