|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-11-07 07:41 UTC] phpbug at tab1 dot clara dot co dot uk
Make sure the odbc.check_persistent is on and that odbc.allow_persistent is on. Set up a database connection called dsnname
Run the script below (substituting [tabname] for a valid table name in your database).
Check that you have persistent connections, ie with the webserver idle make sure your database shows connections from the webserver.
Restart the database or kill the session belonging to the web server.
Re-run the script below and the odbc_exec fails with an error: "connection not open" or smililar depending on your odbc driver.
I have found this effect to be the same with the Postgres odbc driver and the Informix 3.30 odbc driver.
I presume that odbc.check_persistent is supposed to check that the connection is still attached to the database before pconnect gives it to the script?
<?
$dbconn = odbc_pconnect("dsnname","","");
$rid = odbc_exec($dbconn,"select * from [tabname]");
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 17:00:02 2025 UTC |
Here's a patch written according to phpbugs at kevin dot offwhite dot net's suggestion(I hope space and tabs won't be damanged). We're using a similar version(just by replacing SQLGetInfo() with SQLGetConnectAttr()) on a spare machine, and odbc_pconnect() seems to be working so far. Uncommenting out the code for fixing #15758 is a bit scary, but I believe it should be OK. Index: php_odbc.c =================================================================== RCS file: /repository/php-src/ext/odbc/php_odbc.c,v retrieving revision 1.143.2.12 diff -u -r1.143.2.12 php_odbc.c --- php_odbc.c 14 Jun 2003 03:37:30 -0000 1.143.2.12 +++ php_odbc.c 27 Jul 2005 08:47:05 -0000 @@ -2156,6 +2156,29 @@ } /* }}} */ +/* {{{ is_connection_dead */ +static int is_connection_dead(odbc_connection *db_conn) +{ +#if defined(HAVE_IBMDB2) +#else + UCHAR d_name[32]; + SWORD len; +#endif + SQLINTEGER dead; + RETCODE ret; + +#if defined(HAVE_IBMDB2) + ret = SQLGetConnectAttr(db_conn->hdbc, SQL_ATTR_CONNECTION_DEAD, &dead, + 0, NULL); +#else + ret = SQLGetInfo(db_conn->hdbc, SQL_DATA_SOURCE_READ_ONLY, d_name, + sizeof(d_name), &len); + dead = len == 0; +#endif + return ret != SQL_SUCCESS || dead; +} +/* }}} */ + /* Persistent connections: two list-types le_pconn, le_conn and a plist * where hashed connection info is stored together with index pointer to * the actual link of type le_pconn in the list. Only persistent @@ -2282,23 +2305,13 @@ * check to see if the connection is still in place (lurcher) */ if(ODBCG(check_persistent)){ - RETCODE ret; - UCHAR d_name[32]; - SWORD len; - - ret = SQLGetInfo(db_conn->hdbc, - SQL_DATA_SOURCE_READ_ONLY, - d_name, sizeof(d_name), &len); - - if(ret != SQL_SUCCESS || len == 0) { + if(is_connection_dead(db_conn)) { zend_hash_del(&EG(persistent_list), hashed_details, hashed_len + 1); - /* Commented out to fix a possible double closure error - * when working with persistent connections as submitted by - * bug #15758 - * - * safe_odbc_disconnect(db_conn->hdbc); - * SQLFreeConnect(db_conn->hdbc); + /* + * now that we know the connection is dead, just free + * the DBC handle without issuing SQLDisconnect(). */ + SQLFreeConnect(db_conn->hdbc); goto try_and_get_another_connection; } }