php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26012 mssql_fetch_array
Submitted: 2003-10-27 17:05 UTC Modified: 2003-11-20 13:09 UTC
From: boccara at netvision dot net dot il Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 4.3.4RC2 OS: win2k SBS SP4 & Apache 2.0.47
Private report: No CVE-ID: None
 [2003-10-27 17:05 UTC] boccara at netvision dot net dot il
Description:
------------
I have upgraded from 4.3.4 RC1
my program works already about 6 month with the latest version of php.

the probleme is that the fetch of an sql query return additonal non breaking space as result.

this bug is absolutly new, I search in my code hours, and I returned to the 4.3.4 RC1 and everything is Ok now.
 


Reproduce code:
---------------
Function dbFetch ($iResult, &$tabColonne) {

  $iNbCol = 0; 
  $tabColonne = array();
  switch (SGBD) {
    case "MSSQL":
	$tabColonne = mssql_fetch_array($iResult);
    if($tabColonne)
    {
    	$iNbCol = count($tabColonne);
    }
     break;
  }
  return $iNbCol;
}







Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-28 10:42 UTC] iliaa@php.net
Is there a space in the actual SQL data inside the db?
 [2003-10-28 10:52 UTC] boccara at netvision dot net dot il
it's possible ( I didn't check because there is a lot of data).

anyway I used in my request RTRIM to prevent any unwanted space.

note that this bug is really NEW to the actual version
 [2003-10-28 15:38 UTC] boccara at netvision dot net dot il
I made some change, and let me tell you that uou have a BIG bug.
I returned to 4.3.4RC2
I made a request WITHOUT any RTRIM
my data are defined as varchar(100) and NOT as char.
I have located where there is a problem:

query : select a from table test

( a is varchar(100))

when a is blank (without any caractere but not null ) it return the ascii code 32 wich is a space.

if it is not a BUG I would like to understand what it is ???
 [2003-10-28 17:32 UTC] fmk@php.net
The C API provided from Microsoft is the problem in this cse. An ampty column is returned as a single space and not as a true empty column (a string with length 0). It is not possible to see the difference between an empty column and a column with a single space.

In this case it is a bug, but not in PHP! As stated before the PHP extensions sould not attempt to 'fix' data but just present them as is.
 [2003-10-29 03:08 UTC] boccara at netvision dot net dot il
I agree with you, but why I only have this problem with the 4.3.4RC2 version ???????
I remind you that it works with 4.3.4RC1 and older version !
 [2003-10-29 14:34 UTC] fmk@php.net
The code was changed to fix a bug (#25777). This causes an other problem as there is a bug in the mssql library we use to build the extension. It has not been possible to gen an updated version of this library from Microsoft.

Your code seamed to work fine with older versions of the extension, as all char and varchar fields was trimmed for trailing spaces. This is no longer the case and the fact that the library returns a single space when the column is empty and when the column contains a single space is not a problem with the php extension.

For older versions of the extension it was not possible to store a value with spaces at the end, these would be trimmed out by the extension.

The way the extension works now is the correct way (data is passed on from the database to the user ast it is).
 [2003-11-20 12:04 UTC] jro at aucotec dot com
--- Zitat
The code was changed to fix a bug (#25777). This causes an other problem as there is a bug in the mssql library we use to build the extension. It has not been possible to get an updated version of this library from Microsoft
--- Zitat ende

Do you have an Statement of Microsoft for this Bug?
In my Application i'm testing for a value of null and for a blank value (like ''). Its a problem when i'm getting an value of ascii code 32 wich is a space.
why it has not been possible to get an updated version of this library from Microsoft?
 [2003-11-20 12:10 UTC] jro at aucotec dot com
what do you think about an ini-switch like "auto rtim, auto ltrim, auto ltrim and auto rtrim" to solve this problem for the future?
 [2003-11-20 13:09 UTC] fmk@php.net
I have tried to get Microsoft to updet the library for years but DBLIB was discontinued and might not be supported in new versions of the SQL Server! We are still using the LIBS from SQL Server 6.0.

I think the best fix would be to get FreeTDS to work under Win32, and I'm working on that. I don't like the idea of adding ini settings to get arround bugs. You could write a small wrapper function that does this for you if you need it, but I don't see a way to make a working fix as it would make 'a ' become 'a' and that would be wring if you insertd 'a ' into the database.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Dec 04 09:05:54 2022 UTC