| Bug #48324 | oci_bind_by_name() returning wrong id value | ||||
|---|---|---|---|---|---|
| Submitted: | 19 May 1:48am UTC | Modified: | 19 May 5:12pm UTC | ||
| From: | roger dot robins at det dot nsw dot edu dot au | Assigned to: | |||
| Status: | Bogus | Category: | OCI8 related | ||
| Version: | 5.2.9 | OS: | Linux Redhat ES 3.0 | ||
[19 May 5:12pm UTC] sixd@php.net
Passing a -1 length to the oci_bind_by_name call allocates only enough storage for the current size of $id at the time of the call. A size of 1 is used for a null. Instead of -1, pass a length big enough to hold your largest expected return value.

Description: ------------ When INSERTing a record into a table that has a database sequence for calculating the table id (unique identifier) and that sequence's next_val has reached double figures; and you use oci_bind_by_name to return the id of the inserted row; then only the first digit of the two digit row id is returned. Code: $sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($values) $returning"; $id = null; $this->query_start($sql, $params, SQL_QUERY_INSERT); $stmt = $this->parse_query($sql); $descriptors = $this->bind_params($stmt, $params, $table); if ($returning) { oci_bind_by_name($stmt, ":oracle_id", $id, -1, SQLT_LNG); } $result = oci_execute($stmt); $this->free_descriptors($descriptors); $this->query_end($result, $stmt); oci_free_statement($stmt); Reproduce code: --------------- Environment: PHP 5.2.9 compiled again Oracle 10.2 or 11.1 client, connecting to Oracle 10.2 database. './configure' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-mysql=/usr/bin' '--enable-soap' '--with-curl' '--with-xmlrpc' '--enable-mbstring' '--with-openssl' '--enable-zip' '--with-ldap' '--with-oci8=/apps/oraoid/app/oraoid/product/11.1.0/client_1' Expected result: ---------------- When the database table sequence reaches double figures, the correct table (seed) id should be returned as a result of sql INSERT command and calling oci_bind_by_name. Actual result: -------------- The id returned is only the first digit of the real row id.