php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48324 oci_bind_by_name() returning wrong id value
Submitted: 2009-05-19 01:48 UTC Modified: 2009-05-19 17:12 UTC
From: roger dot robins at det dot nsw dot edu dot au Assigned:
Status: Not a bug Package: OCI8 related
PHP Version: 5.2.9 OS: Linux Redhat ES 3.0
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: roger dot robins at det dot nsw dot edu dot au
New email:
PHP Version: OS:

 

 [2009-05-19 01:48 UTC] roger dot robins at det dot nsw dot edu dot au
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-19 17:12 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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 08:01:32 2025 UTC