php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39582 Connection problems after SQL error
Submitted: 2006-11-22 09:35 UTC Modified: 2016-10-15 23:09 UTC
Votes:5
Avg. Score:2.4 ± 1.2
Reproduced:2 of 4 (50.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: lars dot roessiger at gmail dot com Assigned:
Status: Wont fix Package: MSSQL related
PHP Version: 5.2.0 OS: Windows Server 2003
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-11-22 09:35 UTC] 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).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-22 09:56 UTC] 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 10:11 UTC] 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().
 [2014-12-29 01:05 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: fmk +Assigned To:
 [2016-10-15 23:09 UTC] kalle@php.net
-Status: Open +Status: Wont fix
 [2016-10-15 23:09 UTC] kalle@php.net
With MSSQL being removed from PHP as of PHP7.0, and ext/mssql not having a maintainer, I'm gonna close this report as a Won't fix, until maybe one day it will find a new maintainer.

Alternatively you can use sqlsrv from Microsoft if you are on Windows, or pdo_dblib if you are on Unix.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 18:01:23 2020 UTC