php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70869 mssql_fetch_batch tries to allocate 4GB memory
Submitted: 2015-11-06 09:51 UTC Modified: 2016-10-15 23:06 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: m dot subotovic at gmail dot com Assigned:
Status: Wont fix Package: MSSQL related
PHP Version: 5.4.45 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: m dot subotovic at gmail dot com
New email:
PHP Version: OS:

 

 [2015-11-06 09:51 UTC] m dot subotovic at gmail dot com
Description:
------------
Fatal error: Allowed memory size of X bytes exhausted (tried to allocate 4294967296 bytes)

The error above is being shown when using mssql_fetch_batch on two different connections. Look at the test script example.

Test script:
---------------
<?php

function fetchAssoc($link)
{
    $res = mssql_fetch_assoc($link);

    if ($res === false) {
        if (mssql_fetch_batch($link) > 0) {
            $res = mssql_fetch_assoc($link);
        }
    }
    return $res;
}

$link1 = mssql_connect('host', 'user', 'pwd');
mssql_select_db('db', $link1);

$link2 = mssql_connect('host', 'user', 'pwd');
mssql_select_db('db', $link2);

$result1 = mssql_query("SELECT TOP 2 * FROM table", $link1, 1);

while ($row1 = fetchAssoc($result1)) {
    echo "Row from 1 result\n";

    $result2 = mssql_query("SELECT TOP 2 * FROM table2", $link2);
    while ($row2 = fetchAssoc($result2)) {
        echo "Row from 2 result\n";
    }
}

echo "Done";

Expected result:
----------------
Row from 1 result
Row from 2 result
Row from 2 result
Row from 1 result
Row from 2 result
Row from 2 result
Done

Actual result:
--------------
Row from 1 result
Row from 2 result
Row from 2 result

Fatal error: Allowed memory size of X bytes exhausted (tried to allocate 4294967296 bytes)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-07 16:46 UTC] marcosptf at yahoo dot com dot br
have you read this comment on php doc?

http://php.net/manual/en/function.mssql-fetch-batch.php#111642

what version of sql server do you use?

Thanks

marcosptf
:D
 [2015-11-10 09:13 UTC] m dot subotovic at gmail dot com
Yes, I have read this comment.
I use two different connections, not the same.

I use Microsoft SQL Server 2008 R2 (SP1) Standard Edition (64-bit) on Windows NT 6.1
 [2016-10-15 23:06 UTC] kalle@php.net
-Status: Open +Status: Wont fix
 [2016-10-15 23:06 UTC] kalle@php.net
With MSSQL being removed from PHP as of PHP7.0, and ext/mssql not having a maintainer, I'm gonna close this report as a Won't fix, until maybe one day it will find a new maintainer.

Alternatively you can use sqlsrv from Microsoft if you are on Windows, or pdo_dblib if you are on Unix.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Sep 17 13:00:01 2025 UTC