Bug #39582 [Asn->Opn]: Connection problems after SQL error

From: Date: Mon, 29 Dec 2014 01:05:46 +0000
Subject: Bug #39582 [Asn->Opn]: Connection problems after SQL error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189286@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=39582&edit=1

 ID:                 39582
 Updated by:         kalle@php.net
 Reported by:        lars dot roessiger at gmail dot com
 Summary:            Connection problems after SQL error
-Status:             Assigned
+Status:             Open
 Type:               Bug
 Package:            MSSQL related
 Operating System:   Windows Server 2003
 PHP Version:        5.2.0
-Assigned To:        fmk
+Assigned To:        
 Block user comment: N
 Private report:     N



Previous Comments:
------------------------------------------------------------------------
[2006-11-22 10:11:35] lars dot roessiger at gmail dot com

The "hanging script"-problem only occurs when connecting via NETBIOS. When I connect to
the server via TCP/IP, it does not hang.

However, I'm still getting "Unable to select database" when an SQL error occurs when
connecting via mssql_pconnect().

------------------------------------------------------------------------
[2006-11-22 09:56:50] lars dot roessiger at gmail dot com

Tried to reproduce the problem on Linux with FreeTDS:

"Unable to select database" with mssql_pconnect().
No problems with mssql_connect(). Error handler properly finishes.

------------------------------------------------------------------------
[2006-11-22 09:35:16] lars dot roessiger at gmail dot com

Description:
------------
Unexpected behaviour when SQL queries fail.

Reproduce code:
---------------
<?
    $db_host = "";
    $db_user = "";
    $db_pass = "";
    $db_base = "";

    function error_handler($errno, $errmsg)
    {
        echo $errmsg;
        exit(1);
    }

        // script will hang on sql error
    $dbconn = mssql_connect($db_host, $db_user, $db_pass);
        // refreshes will cause sql server to refuse selection of db
    //$dbconn = mssql_pconnect($db_host, $db_user, $db_pass);
    mssql_select_db($db_base, $dbconn);

    error_reporting(0);
    set_error_handler("error_handler");

    if($_GET['error'] == "plain")
        trigger_error("Error", E_USER_ERROR);   // produce error
    else if($_GET['error'] == "sql")
        mssql_query("SELECT asdf FROM asdf");   // produce sql error
?>


Expected result:
----------------
mssql_connect(): On SQL error the script should not hang but finish.

mssql_pconnect(): On SQL error further connection requests should not fail.

Actual result:
--------------
If an SQL error occurs, database connections established with mssql_pconnect() get lost. New
connection requests fail with "mssql_select_db() [function.mssql-select-db]: Unable to select
database".

When using mssql_connect() instead of mssql_pconnect(), execution of the resp. PHP script will hang
(up to 5 minutes). The error handler will finish its job, but PHP does not close the connection to
the browser - it keeps "loading" (although no data is being sent anymore).


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=39582&edit=1


Thread (6 messages)

« previous php.bugs (#189286) next »