Hi All,

I am having contsantly getting the following error:

PHP Fatal error: Out of memory (allocated 4295491584) (tried to allocate 8589934593 bytes)

the line its complaining about is as following hilighted in bold:

<?php
$link = @sybase_connect('****', '***', '****')
        or die("Could not connect !");
echo "Connected successfully";

$sql = "SELECT id_key, nm_value, dt_create
          FROM MERLIN_PROPERTIES";

echo "<table border='1' width='100%' cellspacing=0 cellpadding=0>";
echo "   <tr bgcolor='lightblue'>";
echo "      <td><b>ID KEY</b></td>";
echo "      <td><b>NM VALUE</b></td>";
echo "      <td><b>DT CREATE</b></td>";
echo "   </tr>";

[B]$sql_result = sybase_query($sql,$link);[/B]

Any help would be very much appreciated. Many thanks

Shuel

Dani AI

Generated

Short diagnosis and what to try first

The PHP fatal out-of-memory you reported means the PHP process was asked to hold a very large allocation (so it aborted rather than continuing). Before cranking up memory_limit, verify whether the query is returning an enormous result or a very large LOB; blindly increasing memory just hides the real problem. (php.net)

Quick reproducible tests (very useful)

  • Run the query but limit rows to see whether result size is the culprit (this is exactly the quick test suggested). Example SQL for Sybase:
SELECT TOP 1000 id_key, nm_value, dt_create
FROM MERLIN_PROPERTIES;

Or use a session limit:

SET ROWCOUNT 1000;
SELECT id_key, nm_value, dt_create FROM MERLIN_PROPERTIES;
SET ROWCOUNT 0;

If the limited query works, it confirms a result-size/ buffering problem. (infocenter.sybase.com)

How to avoid buffering the whole result

Older PHP/Sybase clients will buffer whole result sets into PHP memory. Use an unbuffered/streaming fetch so PHP only holds one row at a time (for Sybase: sybase_unbuffered_query($sql,$link, false) and then fetch rows in a loop; call sybase_free_result() when done). On modern PHP builds the old sybase extensions or unbuffered helpers may be missing, so consider using PDO (pdo_dblib / dblib via FreeTDS) or PDO_ODBC and iterate rows. (php.net)

Other diagnostics and practical fixes

  • Check for very large text/blob values: run SELECT MAX(DATALENGTH(nm_value)) ... to find offenders and set a sensible SET TEXTSIZE if you only need prefixes. (infocenter.sybase.com)

  • If streaming isn’t available, process in batches by primary key ranges or add WHERE clauses to page results. Always free result resources after use. If you post server/PHP version and approximate row/column sizes, a short example for streaming or batching can be added.

Recommended Answers

All 2 Replies

If you are working with a huge number of records, maybe sybase is trying to build a table in memory to hold all the results and it's running out of space. If that is a possibility, then you might want to try changing your query as an experiment to limit the number of records by something like "...and id_key < 1000" (based on looking at the keys that you have and picking one that is pretty low in the range). If that works, then you could try increasing the amount of memory (see the post ) and/or by process the input in stages by key range or alphabetically by the name or by date ranges.

same problem but not resolved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.