From: phpbug at chipple dot net Operating system: Win2K 5.00.2195 SP4 PHP version: 4.3.4RC2 PHP Bug Type: ODBC related Bug description: ODBC truncates multi-byte text (w/ MSSQL)
Description: ------------ This bug has been observed with PHP 4.3.3 and 4.3.4RC2. Database: MSSQL 2000 (8.00.760) SP3 I have a MSSQL database with a table containing a column tTitle of type nvarchar(80) (which stands for 80 multi-byte characters). When a string of 60 Japanese double-byte characters (120 bytes) stored in column tTitle is retrieved using PHP's ODBC extension, the value is truncated to 80 bytes. The PHP MSSQL extension retrieves the data correctly. Microsoft's ODBC driver (used from ASP) retrieves the data correctly. MSSQL table structure: CREATE TABLE [dbo].[T_Course] ( [aCourseID] [int] IDENTITY (1, 1) NOT NULL , [tTitle] [nvarchar] (80) COLLATE Japanese_CI_AS NOT NULL ) ON [PRIMARY] GO Test data (CSV): aCourseID,tTitle 1,[string of 60 Japanese double-byte characters] SQL query: SELECT * FROM T_Course WHERE aCourseID=1 Reproduce code: --------------- // ODBC EXTENSION, data truncated $oConn = odbc_connect(C_Gen_sDbDSN,C_Gen_sDbUser,C_Gen_sDbPassword); $oRs = odbc_exec($oConn,"SELECT * FROM T_Course WHERE aCourseID=1"); $aRow = odbc_fetch_array($oRs); // BAD: Title truncated to 80 _bytes_ echo $aRow["tTitle"]; odbc_close($oConn); // MSSQL EXTENSION, data retrieved correctly $oConn = odbc_connect(C_Gen_sDbDSN,C_Gen_sDbUser,C_Gen_sDbPassword); $oRs = odbc_exec($oConn,"SELECT * FROM T_Course WHERE aCourseID=1"); $aRow = odbc_fetch_array($oRs); // GOOD: Complete title retrieved (60 chars=120 bytes) echo $aRow["tTitle"]; odbc_close($oConn); Expected result: ---------------- The ODBC extension should truncate the retrieved data to 80 characters (instead of 80 bytes). Actual result: -------------- The ODBC extension truncates the retrieved data to 80 bytes. -- Edit bug report at http://bugs.php.net/?id=25972&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25972&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25972&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=25972&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=25972&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=25972&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=25972&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=25972&r=support Expected behavior: http://bugs.php.net/fix.php?id=25972&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=25972&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=25972&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=25972&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25972&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=25972&r=dst IIS Stability: http://bugs.php.net/fix.php?id=25972&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=25972&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=25972&r=float