php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26799 divide by zero errors not reported
Submitted: 2004-01-05 16:31 UTC Modified: 2004-01-07 00:06 UTC
From: danielc at analysisandsolutions dot com Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 4.3.4 OS: Windows 2000
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: danielc at analysisandsolutions dot com
New email:
PHP Version: OS:

 

 [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
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-05 16:45 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Nonumber may be divided by zero.
 [2004-01-05 16:52 UTC] danielc at analysisandsolutions dot com
Exactly.  That's why MSSQL considers it an error.  But PHP doesn't report back the error from MSSQL.
 [2004-01-06 18:38 UTC] sniper@php.net
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'..

 [2004-01-06 23:27 UTC] danielc at analysisandsolutions dot com
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
 [2004-01-06 23:27 UTC] danielc at analysisandsolutions dot com
Close it.
 [2004-01-07 00:06 UTC] magnus@php.net
Not a bug => Bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 17:01:31 2024 UTC