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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 01:01:28 2024 UTC