ID: 46575
Updated by: [email protected]
Reported By: ben at thelocust dot org
Status: Open
-Bug Type: MSSQL related
+Bug Type: Feature/Change Request
Operating System: *
PHP Version: 5.2.6
New Comment:
I don't see the error here, your asking SQL server to return 'test_id'
from the table 'test' where 'test_number' doesn't even to 1 or 2, and
since NULL is different from 1 and 2 then why shouldn't it be returned?
I see that more of a bug in the ASP/VBScript drivers, and I don't think
we should put such an inconsistency into because others do it.
I changed the category of this to a Feature/Change request, letting the
extension maintainer decided whenever to do it or not :)
Previous Comments:
------------------------------------------------------------------------
[2008-11-14 16:35:50] ben at thelocust dot org
Description:
------------
When querying a MSSQL database table, and using the "not in" syntax,
PHP's mssql_query will also return rows with NULL in the field
specified.
Reproduce code:
---------------
SQL Server 2000 or 2005
Table "test"
test_id (int) test_name (vchar) test_number (int)
1 Foo 1
2 Bar 2
3 <null> 3
4 Baz <null>
$sql = "select test_id from test where test_number not in (1,2)";
$res = mssql_query($sql);
while ($row = mssql_fetch_array($res)) {
?>
<?=$row['test_id'];?><br/>
<?
}
Expected result:
----------------
In PHP, either using FreeTDS on Linux or the MSSQL extension on
Windows, the above returns:
3
4
In ASP/VBScript or using Query Analyzer on Windows the following is
returned:
3
Windows' MSSQL driver apparently will not compare the "not in" values
to a NULL field. PHP, apparently, will.
This creates and inconsistency between the two platforms.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46575&edit=1