| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2004-01-05 16:31 UTC] danielc at analysisandsolutions dot com
 Description:
------------
MSSQL seems to not like queries that divide by zero -- see the OSQL commands below.  But, PHP doesn't report it as an error.
   osql -Usa
   1> SELECT 0/0 AS FOO
   2> go
   Msg 8134, Level 16, State 1, Server BASE2K, Line 1
   Divide by zero error encountered.
Reproduce code:
---------------
$c = mssql_connect('localhost', 'sa', 'pw');
$result = @mssql_query('SELECT 0/0 AS FOO', $c);
if ($result) {
    $ar = mssql_fetch_array($result, MSSQL_ASSOC);
    var_dump($ar);
} else {
    echo mssql_get_last_message();
}
Expected result:
----------------
Divide by zero error encountered.
Actual result:
--------------
array(1) {
  ["foo"]=>
  NULL
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 05:00:01 2025 UTC | 
Try this script: <?php error_reporting(E_ALL); $c = mssql_connect('localhost', 'sa', 'pw'); $result = mssql_query('SELECT 0/0 AS FOO', $c); echo mssql_get_last_message(); ?> See also: http://www.php.net/manual/en/function.mssql-min-error-severity.php I think this is not really bug as is..the query doesn't actually 'fail'..Interesting. The query produces both a result and an error. I now see that's how mssql intentionally operates. By the way... mssql_min_error_severity() didn't change anything. But, setting mssql_min_message_severity() to 0 caused a PHP warning on the mssql_query() call. Sample script: -------------- $c = mssql_connect('localhost', 'sa', 'pw'); for ($Counter = 0; $Counter < 17; $Counter++) { //mssql_min_error_severity($Counter); mssql_min_message_severity($Counter); $result = mssql_query('SELECT 0/0 AS FOO', $c); echo ' E: ' . mssql_get_last_message(); $ar = mssql_fetch_array($result, MSSQL_ASSOC); echo ' R: ' . gettype($ar['FOO']); echo ' C: ' . $Counter; echo '<br />'; } Output: ------- Warning: mssql_query(): message: Division by zero occurred. (severity 0) in... E: Division by zero occurred. R: NULL C: 0 ... snipped similar output for brevity ... E: Division by zero occurred. R: NULL C: 16