#20911 [NEW]: Trailing null character after mssql datetime field
From: [EMAIL PROTECTED] Operating system: Windows 2000 PHP version: 4.2.3 PHP Bug Type: MSSQL related Bug description: Trailing null character after mssql datetime field When selecting a datetime field from mssql while the following setting is active: ini_set('mssql.datetimeconvert', 0); the field contains a trailing null character which causes havoc when generating XML. Environment: SQL Server 2000 A workaround is to select the datatime field as CAST(.. AS CHAR). Example script to reproduce the problem: ini_set('mssql.datetimeconvert', 0); $iLinkId = mssql_connect('server', 'username', 'pwd'); mssql_select_db('database', $iLinkId); $iResultId = mssql_query( 'SELECT TESTDATE FROM TEST WHERE TEST_ID = 1' ); $aRow = mssql_fetch_array($iResultId); print $aRow[0] . '|'; print strlen($aRow['TESTDATE']); print '|'; print ord( $aRow['TESTDATE'][strlen($aRow['TESTDATE']) - 1] ); print ''; mssql_close($iLinkId) The output looks like this: 2002-12-31 00:00:00|20|0 indicating the string is 20 characters long, and the last character is a null character (\0). -- Edit bug report at http://bugs.php.net/?id=20911&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=20911&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=20911&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=20911&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=20911&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=20911&r=oldversion Not developer issue:http://bugs.php.net/fix.php?id=20911&r=support Expected behavior: http://bugs.php.net/fix.php?id=20911&r=notwrong Not enough info:http://bugs.php.net/fix.php?id=20911&r=notenoughinfo Submitted twice:http://bugs.php.net/fix.php?id=20911&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=20911&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20911&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=20911&r=dst IIS Stability: http://bugs.php.net/fix.php?id=20911&r=isapi
#18169 [Com]: Driver cannot deliver UCS-2 unicode to SQL Server
ID: 18169 Comment by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Analyzed Bug Type: MSSQL related Operating System: Windows 2000 Server PHP Version: 4.1.2 New Comment: If you're using PHP on a Windows platform you can use the PHP COM extension to communicate with SQL Server via ADO. The PHP COM extension is capable of translating UTF-8 to UCS-2 and back if you specify so as the third parameter: $oDb = new COM('ADODB.Connection', NULL, CP_UTF8); This way you can use Unicode UTF-8 within PHP and Unicode UCS-2 within SQL Server with all the translations done for you automatically. HTH, Freddy Vulto Previous Comments: [2002-07-06 07:08:48] [EMAIL PROTECTED] Thanks Marko -I guess this means that if you are to use binary (ie. unicode) data, then COM/ADO is your only option, if SQL Server is the database of your choice. >From yohgaki's answer, I guess also the multibyte encoding functionality lacks proper Unicode support -am I correct in assuming that we will have to move to PHP4.2.x and do our own encoding/decoding through the Win32 API then? [2002-07-05 05:34:22] [EMAIL PROTECTED] PHP's mssql extension uses the Microsoft SQL Server's C API, the "DB-Library for C". Specifically, SQL queries are sent to the server using the dbcmd() function. This function is not binary safe, so inserting UCS2 text or images or any binary data is likely to fail. The DB-Library for C has separate, binary-safe APIs for entering text and images, but they are complicated and difficult to seamlessly integrate to the current mssql extension. Look up the documentation for dbwritetext() if you feel like implementing this change. UTF-8 and UTF-7 are, IIRC, the only Unicode encoding that are guaranteed not to include null characters. They are, therefore, the only encodings that can be reliably used with PHP's mssql extension at this time. [2002-07-05 04:21:52] [EMAIL PROTECTED] You are probably right. However, Unicode is central to making world-wide web applications, and all major database vendors have this posibility. I find it to be a hindrance to wider deployment of large-scale, worldwide php applications. Does anyone know if it is only the MSSQL module? -are there any plans to look into this issue? What are the future directions for PHP and Unicode support? [2002-07-05 04:14:38] [EMAIL PROTECTED] Wide char encoding, UCS2/UCS4/UTF16/UTF32, don't work well with current PHP. I guess SQL Server module is using strlen() or like, that cannot be used with wide char... Fixing this is not simple at all. [2002-07-04 18:10:24] [EMAIL PROTECTED] I have a problem converting UTF-8 (web character encoding) to UCS2 (Microsoft Windows character encoding) using PHP, and storing this in the Microsoft SQL Server 2000 database. My setup is: Windows 2000 Server, with Apache 1.3.24/PHP 4.1.1 and Microsoft SQL Server 2000 Now, as a result of Microsofts Q232580, I will have to do conversion between UTF-8 and UCS-2. For this, I thought I would use the Multibyte String functions. However, this does not seem to work. I am absolutely sure, that I input UTF-8 encoded data into my string, and then I do: $ucs2string=mb_convert_encoding($string,"UCS2","UTF-8"); $sqlStmt="insert into testtbl (tekst) values(N'".($ucs2string)."')"; $rs=$DBCon->Execute($sqlStmt); When I access the database, then I will see something stored, that does not resemble the input at all (most times, I see Japanese/Chinese characters?!??). Furthermore, the insert sometimes comes up with an error, and consequently stores nothing. To me, it seems like either one of these (or both) are flawed: 1. the Multibyte String encoding funtion does not work properly (ie. encoding from UTF-8 to UCS-2 does not happen correctly). 2. The PHP MSSQL driver does not handle unicode data properly, even though the target column in the database is specified as Unicode and N is prepended to the string before insert. This leads me to use ADO (as in the example above), storing UTF-8 encoded data into SQL Server -this is a very short term solution, as data are not sortable in the database (some of it looks like garbage because of the missing encoding). -- Edit this bug report at http://bugs.php.net/?id=18169&edit=1
#19699 [NEW]: 'array_walk()' violates recommended 'allow_call_time_pass_reference=Off'
From: [EMAIL PROTECTED] Operating system: Windows PHP version: 4.2.3 PHP Bug Type: Arrays related Bug description: 'array_walk()' violates recommended 'allow_call_time_pass_reference=Off' The PHP manual contains the following note about 'array_walk()': Note: If func needs to be working with the actual values of the array, specify that the first parameter of func should be passed by reference. Then any changes made to those elements will be made in the array itself. So if you want to let 'array_walk()' pass the third parameter by reference, you're inclined to specify that the third parameter of func should be passed by reference. In the example underneath, the notation '&$userData' is used to specify so: function PrepareBowl($value, $key, &$userData) { print 'Mixed so far... ' . ($userData .= "$value ") . "\n"; } $ingredients = array('peach', 'cherry', 'alchohol'); $bowl = ''; array_walk($ingredients, 'PrepareBowl', $bowl); print "Bowl: $bowl"; This doesn't work however; '$assembly' will not be passed by reference and the output will be an empty 'bowl': Mixed so far... peach Mixed so far... peach cherry Mixed so far... peach cherry alchohol Bowl: Only when you use the '&' notation within 'array_walk()' to specify that the third parameter should be passed by reference: array_walk($ingredients, 'PrepareBowl', &$bowl); the output will be as expected: Mixed so far... peach Mixed so far... peach cherry Mixed so far... peach cherry alchohol Bowl: peach cherry alchohol but, using the recommended php.ini setting 'allow_call_time_pass_reference=Off', you'll receive the warning: Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of array_walk(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. This looks the same like bug 4116 (http://bugs.php.net/bug.php?id=4116), posted Apr 12, 2000. Although this bug is closed with a reply that it works like the replier think it should work, this doesn't seem logic to me because the first parameter *is* passed by reference without specifying; try: array_walk(array('peach', 'cherry', 'alchohol'), 'PrepareBowl', &$bowl); and you'll receive: Fatal error: Only variables can be passed by reference ... Furthermore, I can't see much use of passing a third variable to 'array_walk()' by value, modify it by passing it to func by reference ... without receiving back the modified variable. Would it be a suggestion to let 'array_walk()' receive the third parameter by reference if specified so in the receiving func? This would be in line with the behaviour of the first parameter to func. Freddy Vulto -- Edit bug report at http://bugs.php.net/?id=19699&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=19699&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=19699&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=19699&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=19699&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=19699&r=oldversion Not developer issue:http://bugs.php.net/fix.php?id=19699&r=support Expected behavior: http://bugs.php.net/fix.php?id=19699&r=notwrong Not enough info:http://bugs.php.net/fix.php?id=19699&r=notenoughinfo Submitted twice:http://bugs.php.net/fix.php?id=19699&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=19699&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=19699&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=19699&r=dst
#19699 [Fbk->Opn]: 'array_walk()' violates recommended 'allow_call_time_pass_reference=Off'
ID: 19699 User updated by: [EMAIL PROTECTED] -Reported By: [EMAIL PROTECTED] +Reported By: [EMAIL PROTECTED] -Status: Feedback +Status: Open Bug Type: Arrays related Operating System: Windows PHP Version: 4.2.3 New Comment: I tried using the latest snapshot for Windows: System Windows 9x localhost 4.10 Build Date Oct 3 2002 20:15:03 but I still encounter the same problems. Previous Comments: [2002-10-01 18:51:35] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php4-latest.tar.gz For Windows: http://snaps.php.net/win32/php4-win32-latest.zip [2002-10-01 17:38:45] [EMAIL PROTECTED] The PHP manual contains the following note about 'array_walk()': Note: If func needs to be working with the actual values of the array, specify that the first parameter of func should be passed by reference. Then any changes made to those elements will be made in the array itself. So if you want to let 'array_walk()' pass the third parameter by reference, you're inclined to specify that the third parameter of func should be passed by reference. In the example underneath, the notation '&$userData' is used to specify so: function PrepareBowl($value, $key, &$userData) { print 'Mixed so far... ' . ($userData .= "$value ") . "\n"; } $ingredients = array('peach', 'cherry', 'alchohol'); $bowl = ''; array_walk($ingredients, 'PrepareBowl', $bowl); print "Bowl: $bowl"; This doesn't work however; '$assembly' will not be passed by reference and the output will be an empty 'bowl': Mixed so far... peach Mixed so far... peach cherry Mixed so far... peach cherry alchohol Bowl: Only when you use the '&' notation within 'array_walk()' to specify that the third parameter should be passed by reference: array_walk($ingredients, 'PrepareBowl', &$bowl); the output will be as expected: Mixed so far... peach Mixed so far... peach cherry Mixed so far... peach cherry alchohol Bowl: peach cherry alchohol but, using the recommended php.ini setting 'allow_call_time_pass_reference=Off', you'll receive the warning: Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of array_walk(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. This looks the same like bug 4116 (http://bugs.php.net/bug.php?id=4116), posted Apr 12, 2000. Although this bug is closed with a reply that it works like the replier think it should work, this doesn't seem logic to me because the first parameter *is* passed by reference without specifying; try: array_walk(array('peach', 'cherry', 'alchohol'), 'PrepareBowl', &$bowl); and you'll receive: Fatal error: Only variables can be passed by reference ... Furthermore, I can't see much use of passing a third variable to 'array_walk()' by value, modify it by passing it to func by reference ... without receiving back the modified variable. Would it be a suggestion to let 'array_walk()' receive the third parameter by reference if specified so in the receiving func? This would be in line with the behaviour of the first parameter to func. Freddy Vulto -- Edit this bug report at http://bugs.php.net/?id=19699&edit=1