Edit report at https://bugs.php.net/bug.php?id=69975&edit=1
ID: 69975
Updated by: cmb@php.net
Reported by: jgeert1 at its dot jnj dot com
Summary: PHP is causing Apache to crash when accessing
nvarchar(max) defined columns
Status: Open
Type: Feature/Change Request
Package: ODBC related
Operating System: Windows Server 2012R2
PHP Version: 5.5.26
Block user comment: N
Private report: N
New Comment:
> Anyway if there's anything I can (investigate,test,..), just let
> me know as I really would like this to be resolved.
It might be helpful if you can post an ODBC trace for the given
test script. If the trace is large, it might be best to put it on
<https://gist.github.com/> or someone else, but not
directly in
this ticket. How to create an ODBC trace is described on
<https://support.microsoft.com/en-us/kb/274551>.
And please make
sure there is no confidential information contained in the trace
(password etc.)
Previous Comments:
------------------------------------------------------------------------
[2015-07-02 07:27:19] jgeert1 at its dot jnj dot com
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.
------------------------------------------------------------------------
[2015-07-01 14:42:58] ab@php.net
fix category
------------------------------------------------------------------------
[2015-07-01 14:41:49] ab@php.net
Thanks for the report.
What you say is not quite correct, a lot of ext/odbc related bugs was fixed in the last PHP5
releases, please check the changelog.
Could you please also check #68964? As I didn't have the final response there, while the patch
was already in releases.
What ODBCVER does your phpinfo() show? Which is the SqlServer version?
You should probably know also, that nvarchar and others are long deprecated https://msdn.microsoft.com/en-us/library/ms187993%28v=sql.90%29.aspx
so should not be used. We depend on the underlying library here, it's not about us making
decisions supporting them or not. However it shouldn't crash, that's clear.
Thanks.
------------------------------------------------------------------------
[2015-07-01 08:38:35] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69975&edit=1