php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63485 I don't think the mssql_min_error_severity() function works as it should.
Submitted: 2012-11-11 12:20 UTC Modified: 2016-10-15 23:16 UTC
From: david at sickmiller dot com Assigned:
Status: Wont fix Package: MSSQL related
PHP Version: 5.3.18 OS: CentOS 5.8
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-11-11 12:20 UTC] david at sickmiller dot com
Description:
------------
Hi,

I don't think the mssql_min_error_severity() function works as it should.  At a minimum, the one example in the manual does not make sense (http://www.php.net/function.mssql-min-error-severity#refsect1-function.mssql-min-error-severity-examples).

The example uses a SQL statement with a syntax error.  Regardless of what you set mssql_min_error_severity to, a syntax error is always going to trigger both (a) a PHP Warning and (b) a false return value from mssql_query().  This behavior contradicts the comment above mssql_min_error_severity(1);.  Also, since the code checks the return value from mssql_query(), it's most likely the user will want to use @ to suppress the PHP Warning but that is not shown in the example.

Here's an example that at least shows the mssql_min_error_severity() function doing something:

<?php
mssql_connect($host, $user, $pass);
mssql_select_db($dbname);
mssql_min_error_severity(16);
mssql_min_message_severity(16);
// This SQL has a severity 16 error -- subquery returns multiple rows
$query = mssql_query('SELECT *, (select error from master.dbo.sysmessages) as bad_subquery from master.dbo.sysmessages');
// Prints:
//   PHP Warning:  mssql_query(): message: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. (severity 16)
//   PHP Warning:  mssql_query(): General SQL Server error: Check messages from the SQL Server (severity 16)

mssql_min_error_severity(17);
mssql_min_message_severity(17);
$query = mssql_query('SELECT *, (select error from master.dbo.sysmessages) as bad_subquery from master.dbo.sysmessages');
// Prints nothing



Now, the behavior I disagree with relates to the return value from mssql_query().  Unlike the PHP Warnings, it seems to be unaffected by the min severity settings.  Please see the test script section.

Test script:
---------------
<?php
mssql_connect($host, $user, $pass);
mssql_select_db($dbname);
mssql_min_error_severity(16);
mssql_min_message_severity(16);

// This SQL has a severity 16 error -- subquery returns multiple rows
$query = @mssql_query('SELECT *, (select error from master.dbo.sysmessages) as bad_subquery from master.dbo.sysmessages');
if (!$query) {
        echo "With min severity set to 16, inside custom error handler\n";
} else {
        echo "With min severity set to 16, return code indicates no error from mssql_query()\n";
}


mssql_min_error_severity(17);
mssql_min_message_severity(17);

$query = @mssql_query('SELECT *, (select error from master.dbo.sysmessages) as bad_subquery from master.dbo.sysmessages');
if (!$query) {
        echo "With min severity set to 17, inside custom error handler\n";
} else {
        echo "With min severity set to 17, return code indicates no error from mssql_query()\n";
}

Expected result:
----------------
Expected output:

With min severity set to 16, inside custom error handler
With min severity set to 17, return code indicates no error from mssql_query()

Actual result:
--------------
Actual output:

With min severity set to 16, return code indicates no error from mssql_query()
With min severity set to 17, return code indicates no error from mssql_query()

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-15 23:16 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.
 [2016-10-15 23:16 UTC] kalle@php.net
-Status: Open +Status: Wont fix
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 18:01:23 2020 UTC