php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30690 InterBase: Resource handle from ibase_execute becomes invalid after return
Submitted: 2004-11-05 02:16 UTC Modified: 2007-11-08 19:49 UTC
From: kobaz at kobaz dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.9 OS: Linux 2.6.5
Private report: No CVE-ID: None
 [2004-11-05 02:16 UTC] kobaz at kobaz dot net
Description:
------------
Resource handle from ibase_execute becomes invalid after return

Reproduce code:
---------------
$conn = ibase_connect('localhost:db', 'SYSDBA', 'pass');

function DB_PQuery ($sql, $data) {
  global $conn;
  
  $prepare = ibase_prepare($conn, $sql);
  $result = ibase_execute($prepare, $data);

  //    $A = ibase_fetch_assoc($result);  // uncommenting this will show resource is valid here                                                      
  //    print_r($A);                                                                                                                                 
  
  // after this function returns, the return value is no longer a valid resource                                                                     
  return $result;
}
                   
$result = DB_PQuery("SELECT * FROM testing WHERE a = ?", '1');

$A = ibase_fetch_assoc($result); // fails with: invalid statement handle                                                                             
print_r($A);


Expected result:
----------------
The ibase_fetch_assoc should be successful after DB_PQuery returns.

Actual result:
--------------
Before DB_PQuery returns, $result is a valid resource handle that can be used with ibase_fetch_assoc successfully.

After DB_PQuery returns, the return value is not a valid resource handle despite that nothing in the script has modified it.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-07 14:21 UTC] abies@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

When $prepare goes out of scope, it is cleaned up along with all the resources that depend on it. That includes any results that it created.

 [2005-02-09 18:16 UTC] danielc@php.net
While this behavior may be intentional on your part, I strongly request it be changed.

1) No other DBMS extension in PHP does this.
2) This makes writing programs using ibase very difficult.
3) This makes it impossible to write abstraction packages, such as PEAR DB (which I'm the lead of).
 [2005-02-09 20:32 UTC] kobaz at kobaz dot net
I have a workaround for this bug:

$PQUERY = array();
$curpquery = 0;


function DB_PQuery ($sql, $data) {
  global $PQUERY, $conn;
  
  $PQUERY[$curpquery] = ibase_prepare($conn, $sql);
  $result = ibase_execute($PQUERY[$curpquery], $data);

  $curpquery++;
  return $result;
}

I agree with the previous poster that the result from prepare being destroyed after it goes out of scope is very inconsistant with the rest of the database interfaces for php and makes coding for interbase awkward.
 [2005-02-09 20:33 UTC] kobaz at kobaz dot net
Er, and of course add the extra global variable, but you get the point.
 [2007-11-08 19:49 UTC] lwe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed in HEAD and PHP_5_3
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun May 19 13:01:26 2019 UTC