|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2004-07-21 11:22 UTC] jmelville at selectaustralasia dot com dot au
 Description: ------------ Upgraded an existing server from PHP 4.3.2 to 4.3.8, Apache 1.3 on Windows 2000 SP4. Database is SQL Server 2000 SP4 on the same machine. All SQL queries that previously returned an empty string (e.g. the varchar column in the database contains an empty string and is not NULL) now return a single space character. I've confirmed in Query Analyser that the fields are definitely empty. Note the sample uses mssql_fetch_object() but I've also checked mssql_fetch_array() and it does the same thing. This is the same as bug #9854 but that bug is closed and refers to PHP 4.0.x, whereas this server has never run anything older than 4.3.x Thanks, Julian. Reproduce code: --------------- $sql = "SELECT TOP 5 * FROM jobs; $rs = mssql_query($sql); while ($job = mssql_fetch_object($rs)) { print "rec_id: '$job->rec_id' fax: '$job->fax' \n"; } Expected result: ---------------- rec_id: '45336' fax: '' rec_id: '40659' fax: '09 379 7785' rec_id: '44934' fax: '' Actual result: -------------- rec_id: '45336' fax: ' ' rec_id: '40659' fax: '09 379 7785' rec_id: '44934' fax: ' ' PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 12:00:01 2025 UTC | 
Hi. Following script ... <?php $rConn = mssql_connect('localhost','PHPBB_User','PHPBB_User'); $rResults = mssql_query('SELECT user_icq,LEN(user_icq) AS user_icq_len FROM PHPBB_User.phpbb_users'); while ($row = mssql_fetch_assoc($rResults)) { var_export($row); echo '<br />Length of user_icq = ' . strlen($row['user_icq']) . '<br /><br /><br />'; } mssql_free_result($rResults); mssql_close($rConn); ?> produces output of ... array ( 'user_icq' => ' ', 'user_icq_len' => 0, ) Length of user_icq = 1 array ( 'user_icq' => '1711757', 'user_icq_len' => 7, ) Length of user_icq = 7 array ( 'user_icq' => ' ', 'user_icq_len' => 0, ) Length of user_icq = 1 Which is clearly wrong! The length being returned by SQL is 0, the data being returned by PHP is ' '. The data via enterprise manager is ''. I'm using Sambar Server V6.1 Beta 3, PHP V5.0.0 (about to upgrade to V5.0.1). MS SQL 2000 SP3 Developer Edition all on a Windows XP Pro. But none of this seems to be making any difference. According to all the comments made, this was broken a LONG time ago. It seems that a small patch HAS been applied to the source (php_mssql.c line 793-797), but is under a compiler directive of ilia_0. (Is this Ilia Alshanetsky? If so, great article in PHP|Architect about contexts!!!). The code is in the php_mssql_get_column_content_with_type() function. ... case SQLTEXT: { int length; char *data = charcol(offset); length=dbdatlen(mssql_ptr->link,offset); #if ilia_0 while (length>0 && data[length-1] == ' ') { /* nuke trailing whitespace */ length--; } #endif ZVAL_STRINGL(result, data, length, 1); break; } ... The macro ZVAL_STRINGL is ... #define ZVAL_STRINGL(z, s, l, duplicate) { \ char *__s=(s); int __l=l; \ (z)->value.str.len = __l; \ (z)->value.str.val = (duplicate?estrndup(__s, __l):__s); \ (z)->type = IS_STRING; \ } If someone can recompile the code, can they do so WITHOUT the directive first but put in some debugs (forget thread safeness, only testing) and show what the value of length in the assignment from dbdatlen(mssql_ptr->link,offset) and what happens if the macro is called with a 0 rather than a 1.If have installed php version 4.3.8 and 5.0 but with both versions some sort of the same problem is comming up. When i select all records from a View stored in MS SQL 2000 ("SELECT * FROM View_name) i get all the records while the view on SQL server is definied as SELECT * FROM Table WHERE field IS NOT NULL. When i run this last query in my query analyser the result is less records then when i start the view query with my php application. I think this has something to do with this same problem. Winfred