PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #42765 PDO ODBC: Long binary field in query result crashes PHP ("Out of memory" error)
Submitted:26 Sep 2007 11:00am UTC Modified: 7 May 2009 1:07pm UTC
From:sms at inbox dot ru Assigned to:pajoye
Status:Assigned Category:PDO related
Version:5.2.4 OS:Windows 2000 SP4
Votes:11 Avg. Score:4.8 ± 0.4 Reproduced:11 of 11 (100.0%)
Same Version:3 (27.3%) Same OS:0 (0.0%)
View/Vote Add Comment Developer Edit Submission

Have you experienced this issue?
Rate the importance of this bug to you:

[26 Sep 2007 11:00am UTC] sms at inbox dot ru
Description:
------------
With PDO ODBC I can't get long binary data from Microsoft SQL Server
(image and varbinary(MAX) fields). PDO->query, PDOStatement->execute()
always result in PHP "Out of memory" error, even if output contains no
rows.
The same queries work fine with ODBC unified extension.

Reproduce code:
---------------
<?php
$dbh=new PDO('odbc:Driver={SQL
Server};Server=localhost;Database=test','user','pass');
$dbh->query("select [nbin] from [atts] where [id]=1");
?>

Expected result:
----------------
No PHP fatal errors

Actual result:
--------------
PHP Fatal error:  Out of memory (allocated 262144) (tried to allocate
4294967295 bytes) in D:\Web\test.php on line 3
[27 Sep 2007 6:07pm UTC] carlton dot whitehead at cebesius dot com
I encountered this bug with this setup:
Windows Server 2003 SP2 32bit
IIS 6
PHP 5.2.4
MS SQL Server 2005 Express SP2

PDO ODBC reproduce code:
---------------
<?php
// lobtestPdoOdbc.php
try
{
    $db = new PDO('odbc:fmarchive_mssql', 'change', 'me');
  
    $stp = 'SELECT attdata FROM fm_faxin_att WHERE id = 119085913400004
AND attid = 0'; // statement to prepare
    $ps = $db->prepare($stp);
    $execResult = $ps->execute();
    var_export($execResult, true);
}
catch (PDOException $e)
{
    die($e->getMessage());
}
?>

Expected result:
----------------
output to browser: true

Actual result:
--------------
*Fatal error*: Out of memory (allocated 262144) (tried to allocate
4294967295 bytes) in *C:\Inetpub\wwwroot\FMarchive\lobtestPdoOdbc.php*
on line *9*

plain ODBC reproduce code:
--------------------------
<?php
// lobtestOdbc.php
$res = odbc_connect('fmarchive_mssql', 'change', 'me');
if (!$res) { die ('failed to connect'); }

$stp = 'SELECT attdata FROM fm_faxin_att WHERE id = 119085913400004 AND
attid = 0'; // statement to prepare
$ps = odbc_prepare($res, $stp);
if (!$res) { die ('failed to prepare statement'); }

$execResult = odbc_execute($ps);
echo var_export($execResult, true);
?>

Expected result:
----------------
output to browser: true

Actual result:
--------------
output to browser: true
(this indicates odbc_execute worked correctly)
[10 Jun 2008 9:06am UTC] csa at dside dot dyndns dot org
I got the same problem on Linux (64bit, php 5.2.6). Actually, the
problem is existing in all configurations. I have take a brief look
through php sources. The bug is in pdo_odbc code and affects all
architectures and underlying database engines.

Actually it is in 'ext/pdo_odbc/odbc_stmt.c', function
'odbc_stmt_describe'. The 'displaysize' variable is expected to contain 
estimated size of the column. This could be a negative number if BLOB or
TEXT data is stored (since the record sizes could seriously vary).
However, later in this function the check on data size does not consider
negative numbers. This causes the described behavior. This patch solves
problem for me:

http://dside.dyndns.org/projects/patches.dir/php-ds-odbc_blob.patch

A Linux user trying to access MSSQL over FreeTDS may be interested in
the following patches as well: 
http://dside.dyndns.org/projects/patches.dir/freetds-ds-odbc.patch
http://dside.dyndns.org/projects/patches.dir/php-ds-odbc64.patch
[10 Jun 2008 9:08am UTC] csa at dside dot dyndns dot org
By the way feel free to contact me on csa@dside.dyndns.org if you have
problems with this patches.
[3 Oct 2008 3:34pm UTC] jeffreybolle at gmail dot com
I had the same problem recently. I'd like to thank csa for the great
source code patch.  Recompiling the source under windows wasn't easy and
it took me many hours to piece together all the software and libraries
required.  The result was a fixed extension that can access large blob
files, this has been tested under Windows Vista 32bit.
I thought I'd post a link for the compiled extension (PHP 5.2.6) in case
any other windows users want to make use of this fix without going
through the hassle of learning how to compile PHP from source.

http://s3.paramorphicdesigns.com/random/php/php_pdo_odbc.dll

If there are any problems feel free to contact me at
Jeffreybolle@gmail.com

Jeffrey
[3 Oct 2008 9:41pm UTC] pajoye@php.net
Thanks for the patches and testing.

About compiling php on windows, take a look here:

http://wiki.php.net/internals/windows
[25 Apr 2009 2:50pm UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

[29 Apr 2009 10:44am UTC] skettler@php.net
Confirmed not fixed with latest PHP 5.2 snapshot VC6 x86 Thread Safe
(2009-Apr-27 00:00:00):

Fatal error: Out of memory (allocated 262144) (tried to allocate
4294967295 bytes)

Current workaround is getting the length of the image, retrieving chunks
of 4096 characters and putting them back together in PHP.

SQL-Queries for this workaround look like these:

    SELECT DATALENGTH(imagefield) AS imagelength FROM imagetable WHERE
imageid = ?

    SELECT CAST(SUBSTRING(imagefield, offset, length) AS VARCHAR(4096))
AS imagechunk FROM imagetable WHERE imageid = ?

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC