PHP choking on MS SQL queries [UPDATE]

UPDATE: It looks like the line $result = mssql_query("$query", "$connect, 1"); is the problem, but I have no idea why the result would be so large. Any help is greatly appreciated.

Original post:

I’ve been having some problems getting a script to work with an MS SQL server, and while I’ve got most everything under control, there’s one piece of the puzzle I can’t seem to solve. I can retrieve results from the server ONLY if my result would contain a single row. Anything greater, and I get the following error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 56 bytes)

There should only be ten rows in the query, so I really don’t understand what’s going on. I’ve tried tinkering with this to up the memory limit to 120MB, but got similar results. I would greatly appreciate any insights.

The test code I’ve been using (sans my connection info) is:

[code]$query = “SELECT * FROM Inventory WHERE
ITEM_NUMBER like ‘AUDI-000%’”;

$result = mssql_query("$query", “$connect, 1”);

perform the query

fetch the data from the database

while($row = mssql_fetch_array($result)) {
print("$row[0], $row[4]n");

close the connection


Try running the query directly on the server, and see if you get the results that you’re expecting. Also, keep in mind that using an asterisk (*) to define the return values of a query means to return ALL fields. Some fields may contain lots of data, resulting in a large result set. Best is to only have those fields returned that you will actually use (in this case, the 1st and 5th field).

Sponsor our Newsletter | Privacy Policy | Terms of Service