php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26820 mssql_fetch_row BIT field problem
Submitted: 2004-01-06 15:56 UTC Modified: 2005-11-18 19:58 UTC
Votes:9
Avg. Score:3.7 ± 0.9
Reproduced:8 of 9 (88.9%)
Same Version:2 (25.0%)
Same OS:2 (25.0%)
From: subspace at wanadoo dot nl Assigned: fmk (profile)
Status: Closed Package: MSSQL related
PHP Version: 4CVS-2004-02-06 OS: Debian Linux 2.4.21
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: subspace at wanadoo dot nl
New email:
PHP Version: OS:

 

 [2004-01-06 15:56 UTC] subspace at wanadoo dot nl
Description:
------------
Fields that have the SQL type 'bit' and are nullable return string(1) "0" for both 0 (false) and NULL values, when using mssql_fetch_row and similar.

Expected behavior would be to return bool(false) for NULL values.

Reproduce code:
---------------
function vdump($value) {
	ob_start();
	var_dump($value);
	$result = ob_get_contents();
	ob_end_clean();
	return trim($result);
}

$db = mssql_connect('servername', 'username', 'password');
mssql_query("CREATE TABLE #demo (bitfield BIT NULL, tinyfield TINYINT NULL)", $db);
mssql_query("INSERT INTO #demo (bitfield,tinyfield) VALUES (0, 0)", $db);
mssql_query("INSERT INTO #demo (bitfield,tinyfield) VALUES (1, 1)", $db);
mssql_query("INSERT INTO #demo (bitfield,tinyfield) VALUES (NULL, NULL)", $db);

$result = mssql_query("SELECT * FROM #demo", $db);
while ($row = mssql_fetch_row($result))
	echo "bit: " . vdump($row[0]) . "\t tiny: " . vdump($row[1]) . "\n";

mssql_query("DROP TABLE #demo", $db);


Expected result:
----------------
bit: string(1) "0"	 tiny: string(1) "0"
bit: string(1) "1"	 tiny: string(1) "1"
bit: bool(false)	 tiny: bool(false)

Actual result:
--------------
bit: string(1) "0"	 tiny: string(1) "0"
bit: string(1) "1"	 tiny: string(1) "1"
bit: string(1) "0"	 tiny: bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-19 01:03 UTC] subspace at wanadoo dot nl
Accidentally clicked hit Submit before I was done typing..
Using 4.3.5RC2-dev CVS 200401190430 and Debian package freetds-dev 0.61-5 the result is now:

X-Powered-By: PHP/4.3.5RC2-dev
bit: int(0)      tiny: int(0)
bit: int(1)      tiny: int(1)
bit: int(0)      tiny: NULL

All the strings are now ints, but as you can see the expected NULL value is still not there.
 [2004-01-19 12:21 UTC] sniper@php.net
Just to clarify: Expected behaviour is that return values are NULL for NULL. (definately NOT bool(false) like you suggested in your first comment)

 [2004-02-06 11:35 UTC] sniper@php.net
One more information is needed: what was the configure line used to configure PHP?

 [2004-02-06 13:44 UTC] subspace at wanadoo dot nl
./configure --with-mssql --without-mysql
The mysql option is irrelevant though. 
FreeTDS package installed: freetds-dev    0.61-5

X-Powered-By: PHP/4.3.5RC2

bit: int(0)      tiny: int(0)
bit: int(1)      tiny: int(1)
bit: int(0)      tiny: NULL
 [2004-02-21 05:45 UTC] egarcia at egm dot as
I have the same problem in Windows XP, Windows 2000, using MSSQL 2000.

I call a store procedure that returns data using rollup over a bit field.  In the sumarized data MSSQL return NULL in the bit field but PHP give me a zero (0).

The expected result is to get the NULL value data.

The example in the posted message is TOTALLY replicable in my system.
 [2004-02-25 14:53 UTC] fmk@php.net
On Win32 this is caused by a bug in dblib (the Microsoft library used to build the extension).
 [2004-10-18 20:39 UTC] freddyz77 at tin dot it
dblib use by default TDS protocol 4.2. This protocol do not support null bits so it return 0 instead. Use protocol 7.0 or more (8.0 for mssql2k). This can be configured using FreeTDS (but not using MS dblib).
 [2005-11-18 19:58 UTC] fmk@php.net
This problem has been fixed in FreeTDS. Works on both Windows and Linux.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 07 11:01:28 2024 UTC