php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3723 Cross-nested connect/close fails
Submitted: 2000-03-03 19:59 UTC Modified: 2002-10-02 12:13 UTC
From: sdelmont at loquesea dot com Assigned:
Status: Closed Package: ODBC related
PHP Version: 4.3.0-dev OS: Win2000 Pro
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sdelmont at loquesea dot com
New email:
PHP Version: OS:

 

 [2000-03-03 19:59 UTC] sdelmont at loquesea dot com
Cross-nested connections to the same ODBC Source fails.

It seems the first odbc_close() closes all other connections to the same DSN.

This works OK... (Correctly nested)
   $A = odbc_connect( DSN );
   $B = odbc_connect( DSN );
   odbc_exec( $A );
   odbc_exec( $B );
   odbc_close( $B );
   odbc_close( $A );

This works OK... (Non nested)
   $A = odbc_connect( DSN );
   odbc_exec( $A );
   odbc_close( $A );
   $B = odbc_connect( DSN );
   odbc_exec( $B );
   odbc_close( $B );

This works FAILS... (Cross-nested)
   $A = odbc_connect( DSN );
   $B = odbc_connect( DSN );
   odbc_exec( $A );
   odbc_close( $A );
   odbc_exec( $B );
   odbc_close( $B );

Warning: Bad ODBC connection number (1) in xxxx.php on line [line number for 'odbc_exec( $B );']

Using different DSNs works... even if the two DSNs point to the same database.

I tested it using PHP 3.0.15 and 4 beta 4, using JET (Access) and MSSQL.

This is a serious problem if you use ODBC for PHPLIB, which doesn't close its connections, and use the same DSN elsewhere on your code.

The only workaround seems to either use a separate DSN for PHPLIB and other queries, or change PHPLIB so it closes the database connections after page_open and reopens it at page_close


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-01 15:21 UTC] hholzgra@php.net
connection handles are reused when connecting with same dsn
instead of opening a new connection, so close will close the connection for both connects

there should be an optional force_new parameter or flag
like with mysql_connect

changed to feature request
 [2002-10-02 12:13 UTC] kalowsky@php.net
Hartmut the suggested feature exists in new odbc code, but won't ever been seen in the ODBCv2 code.  Having multiple optional variables won't happen... the code becomes too confusing then.

The code itself is fine, the behavior you're seeing is what is expected.  Hartmut explained this rather nicely.  One simple solution to doing this is to use different usernames or passwords which will cause the asked for behavior.  

This behavior actually falls inline with the way ODBC is expected to work (handles method etc).
 [2003-08-05 09:15 UTC] RMartins at pt dot xrt dot com
At least, a counter should be added, so that if you call open 4 times (same DSN) then only after 4th close call should the connection actually be released.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 23:01:30 2024 UTC