|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-09-26 11:00 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
Patchespatch-blob-uninitialized-odbc_stmt.c (last revision 2016-09-21 15:26 UTC by amistry at am-productions dot biz)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 09:00:01 2025 UTC |
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)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 = ?I'm trying to reproduce this. Could you confirm some details so I can make sure I'm changing the right thing? cmb's notes about initializing a value to 0 relate to a different function. This report is for a few versions of PHP 5.x, but odbc_stmt_describe looks largely the same between the PHP-5.6 branch and master. I'm testing with master on Debian 8. I tried both the FreeTDS and the MS ODBC drivers, connecting to SQL Server 2016. I tried this simple script: <?php $pdo = new PDO(...); $stmt = $pdo->query("select cast(1 as varbinary(max)) as col"); var_dump($stmt->fetchAll()); I didn't get an error with either driver.