php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29383 A SELECT statement returns instead of an empty value, a value containing space
Submitted: 2004-07-26 03:46 UTC Modified: 2006-05-04 20:13 UTC
Votes:15
Avg. Score:4.9 ± 0.3
Reproduced:13 of 13 (100.0%)
Same Version:5 (38.5%)
Same OS:6 (46.2%)
From: gunther at ultraconsulting dot com Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 4.3.7, 5.0.0 OS: Windows 2000
Private report: No CVE-ID: None
 [2004-07-26 03:46 UTC] gunther at ultraconsulting dot com
Description:
------------
A SELECT statement returns instead of an empty value for a varchar field, a value containing a single space. Therefore using the empty() directive will not work anymore.
Problem only happens with php_mssql.dll from year 2004 for PHP version 4.3.7 and 5.0.0. Using a previous dll from 3/13/03 (4.3.2-RC1) for instance solves the problem ... but might cause others.


Reproduce code:
---------------
<?php
$db_host = 'localhost';
$db_user = 'sa';
$db_pass = '';

    if ($dbh = mssql_connect($db_host, $db_user, $db_pass)) {
		print ('<br><br>DB: "'.$db_name.'" connected');
	} else {
		print ("<br>DB NOK ");
		exit;
	} 


 $query = 'SELECT * FROM mydb WHERE id = 1';

  $result = mssql_query($query, $dbh);
  {
      if ($row = mssql_fetch_array($result, MSSQL_ASSOC)) {
          print_r($row);
          print("\n<br>(" . $row['id'] . ')');
      }
  }
?>

Expected result:
----------------
...
()

Actual result:
--------------
...
( )


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-26 04:49 UTC] gunther at ultraconsulting dot com
php_mssql.dll up to PHP 4.3.3 is working fine, problem first started with PHP 4.3.4
 [2004-07-26 14:25 UTC] gunther at ultraconsulting dot com
This is the same as Bug #29292 .. didn't find that one before ...
 [2004-09-22 02:35 UTC] gunther at ultraconsulting dot com
It seems this problem is a long term problem as it was first reported a year ago. Not quite sure why the developers are tagging these reports as 'Bogus'. Everybody using PHP 4.3.3 and higher and MSSQL is affected. The problem is definetely in the php_mssql.dll as the version 4.3.2 dll is working fine, even with PHP 4.3.8.
There is no way to upgrade to PHP 5.0.x as the functioning dll doesn't work with 5.0.
Any clues if and when this bug will be fixed? 
Or at least a workaround for this bug without changing thousands of lines of code withing the application.
 [2004-09-30 12:52 UTC] andreyra at chtivo dot ru
I have the same experience on version 4.3.8 - 4.3.9. Thank for advice to use dll from version 4.3.2. It really solves a problem :).
 [2004-11-05 09:43 UTC] dcrignon at adequasys dot com
I exaclty have the same problem!

In our intranet Php Solution, we can't upgrade from php 4.3.3 if we use mssql database.

With Oracle or MySql, no problem, we can go to 4.3.9 or 5.0.

Now, a new element. On a customer installation, we need Apache 2.0.52 with SSL and in that case, PHP 4.3.3 is really unstable... So we need to go to 4.3.8 or 4.3.9 but we can't, because of MSSQL bug with this space returned instead of empty string !!!

Please PHP Team, any solution ???

Thanks,

David
 [2004-12-21 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-07-28 20:25 UTC] mcknightj at lovullo dot com
Not sure if I missed where this was addressed, but I'm having this problem after upgrading from 4.3.2 to 4.3.11.  We're using php on windows 2003 IIS and have reviewed both this bug report and bug #29292 (listed as bogus).

Reviewing the problem it looks like an empty column is being returned as a single space value.  Null values are being correctly returned but empty varchar fields are not.  I have reviewed the data in enterprise manager, php through IIS, ????, and access through ODBC.  In all the cases null's are reported as nulls, strings as strings and empty columns as empty columns (except php).  This is probably a problem with the windows db library and not php but it would be easier to correct here rather then php code until microsoft updates their library.

Here is an example of what results we get.
DATA:
	id	|	name
==============================
	1	|	'my name'
	2	|	<NULL>
	3	|	''

PHP: [echo $result['id']." - '".$result['name']."'";]
	1 - 'my name'
	2 - ''
	3 - ' '



The change happened around 4.3.4 with the following change in php_mssql.c:
#if ilia_0
	while (length>0 && data[length-1] == ' ') { /* nuke trailing whitespace */
		length--;
	}
#endif


Maybe this could be updated to the following to handle the single space problem with empty strings:
	if (length == 1 && data[0] == ' ') { /* nuke whitespace from empty string */
		length = 0;
		data = '';
	}

Please let me know if you need any additional info or let me know if a work around is already present (other then reverting back to 4.3.3).
 [2005-08-02 00:12 UTC] mcknightj at lovullo dot com
To answer the question from 13 Dec 2004, the current snapshot links are displaying the same problem.

Also the bug is currently listed as 'No feedback', is there a way to roll it back to open again??  Don't want to go through and open a new bug with the same problem.
 [2005-09-06 16:52 UTC] mcknight at chek dot com
Since it seems that no one wants to work on this we made the changes we needed to the source and recreated the dll.  If you are having the same problem you can either build a new php_mssql.dll or email me for a copy of ours.
 [2006-05-04 19:32 UTC] bhiggins at gmail dot com
We are experiencing this bug with PHP 5.1.2 and sybase-ct.

I can't believe this has gone unfixed for so long.
 [2006-05-04 19:44 UTC] tony2001@php.net
The bug is in ntwdblib.dll, please complain to Microsoft.
 [2006-05-04 20:05 UTC] gunther at ultraconsulting dot com
Thx!
That last statement sounds familiar but doesn't help to fix the problem. It also does not explain why the older PHP version is handling it correct. Isn't there a way to get a workaround like mcknight found. I froze the current installation and cannot upgrade ... might try mcknight contribution.
 [2006-05-04 20:13 UTC] tony2001@php.net
See last comment in http://bugs.php.net/bug.php?id=26996
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC