|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-07-01 08:38 UTC] jgeert1 at its dot jnj dot com
Description:
------------
if you have a MS SQL Database with a table that contains columns defined as NVARCHAR(MAX), PHP will crash Apache when executing the odbc_fetch_array function.
Error noted in the Windows Event viewer:
Faulting application name: httpd.exe, version: 2.4.9.0, time stamp: 0x53258cd5
Faulting module name: MSVCR110.dll, version: 11.0.51106.1, time stamp: 0x5098826e
Exception code: 0xc0000005
Fault offset: 0x000000000003c664
Faulting process id: 0x5c4
Faulting application start time: 0x01d0b31ba3eb507f
Faulting application path: D:\wamp\bin\apache\apache2.4.9\bin\httpd.exe
Faulting module path: C:\windows\system32\MSVCR110.dll
Report Id: 2d47d2ee-1f12-11e5-943b-005056915a28
Additional info:
The ODBC driver sees the NVARCHAR(MAX) column as a NVARCHAR(0) column. Probably the zero is causing the odbc driver to loop and consume all available memory.
As a workaround I've changed the DSN to use "SQL Server" instead of "SQL Server Native Client 10.0". This is an "old" driver (version 6) which does not support MARS but at least does not cause Apache to crash. It sees the NVARCHAR(MAX) columns as NTEXT columns with a maximum (maxint)size.
Test script:
---------------
$dbs = odbc_connect("Driver={SQL Server Native Client 10.0"}";Server=MYSERVER1;Database=MYDBS;MARS_Connection=Yes;,"username","password",SQL_CUR_USE_ODBC);
$result = odbc_exec($dbs, "select * from Table1");
// Table1 should have a column defined as "NVARCHAR(MAX)"
$row = odbc_fetch_array($result);
// Apache is crashing when executing the odbc_fetch_array
Expected result:
----------------
Please provide support for NVARCHAR(MAX) columns in all odbc implementations for PHP. I did the test with all recent versions of PHP (except version 7) but all of them crash when accessing this type of column though odbc.
I know this has been reported many times before, but it has never been finally resolved by putting the support into the binaries for all versions of php.
Actual result:
--------------
Crash of Apache.
Patchesodbc-wvarchar-native-draft (last revision 2015-07-02 14:17 UTC by cmb@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 02:00:01 2025 UTC |
Thanks for your fast reply. Don't get me wrong here, I'm really satisfied with the work that you guys are doing here. And I'm even impressed by the quality of it. I just looked at #68964 and yes it's almost the same issue. I also had that same error in the beginning (memory exhausted), but when I changed the max memory limit in php.ini to 1024M, the error did not show up again, instead Apache started crashing as a result of it. The database server (seperate system) is running SQL Server 11.0.5058 (SQL Server 2012). The ODBC driver I'm using is "SQL Server Native Client 11.0" (2011.110.2100.60). The database is using some tables with columns defined as "nvarchar(max)", this type is not deprecated as you've mentioned, it's even recommended to use them ("ntext", "text" and "image" types are deprecated). When I'm using the "SQL Server Native Client 11.0" odbc driver, I notice that the columns are reported (using the odbc_columns calls) as "nvarchar(0)". But when I'm using the "SQL Server" odbc server, these same columns are reported as "ntext" with a size of 2147483646 eventhough it's the same column in the database wich is indeed defined as "nvarchar(max)". Anyway if there's anything I can (investigate,test,..), just let me know as I really would like this to be resolved. Currenlty I'm using the 64-bit versions of Apache and PHP. Thanks.This is the testscript I've used: $db_datastage = odbc_connect($dsn,$user,$pwd,SQL_CUR_USE_ODBC); $res = odbc_exec($db_datastage,"select top 10 * from SN.cmdb_ci"); while ($row = odbc_fetch_array($res)) { var_dump($row); } odbc_close($db_datastage); This trace is the failing one (using "SQL Server Native Client 11.0" as driver): https://gist.githubusercontent.com/anonymous/757e0f1fabeefbbb1abb/raw/SQLLOG1 This trace is the successful one (using "SQL Server" as driver): https://gist.githubusercontent.com/anonymous/6d59f9903ca76d43095d/raw/sqllog2 It looks like it's having an issue when fetching the result (2nd result) as it's displaying: DIAG [01004] [Microsoft][SQL Server Native Client 11.0]String data, right truncation (0) Looks like a small buffer problem somewhere?