Stack Out Of Space Error
I'm having a little trouble with a query I've written (please see below).
<?php
require("phpfile.php");
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Opens a connection to a MySQL server
$connection=mysql_connect ("hostname", $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
$query = "SELECT userdetails.userid
, detectinglocations.locationid
, detectinglocations.locationname
, finds.findid
, finds.locationid
, finds.findosgb36lat
, finds.findosgb36lon
, finds.dateoftrip
, finds.findcategory
, finds.findname
,finds.finddescription
, finds.detectorsettings
, finds.pasref
, finds.additionalcomments
, detectors.detectorname
, searchheads.searchheadname
FROM userdetails, detectinglocations, finds, detectors, searchheads
WHERE finds.userid=userdetails.userid
AND finds.locationid=detectinglocations.locationid
AND finds.detectorid=detectors.detectorid
AND searchheads.detectorid=detectors.detectorid";
$result = 开发者_StackOverflow社区mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("findid",$row['findid']);
$newnode->setAttribute("locationid",$row['locationid']);
$newnode->setAttribute("locationname",$row['locationname']);
$newnode->setAttribute("dateoftrip",$row['dateoftrip']);
$newnode->setAttribute("findcategory",$row['findcategory']);
$newnode->setAttribute("findname",$row['findname']);
$newnode->setAttribute("finddescription",$row['finddescription']);
$newnode->setAttribute("detectorname",$row['detectorname']);
$newnode->setAttribute("searchheadname",$row['searchheadname']);
$newnode->setAttribute("detectorsettings",$row['detectorsettings']);
$newnode->setAttribute("pasref",$row['pasref']);
$newnode->setAttribute("additionalcomments",$row['additionalcomments']);
}
echo $dom->saveXML();
?>
When I run the php script through my web browser it retrieves the correct data, but when I run this through the HTML page I get an 'Out of Stack' error. From what I've read on the web, I think it may be because the SQL query is too complex.
Could you tell me please can an overly complex SQL query cause this type of error?
There's something wrong/unexpected with your data.
1) Do a file_put_contents("somedumpfile", var_export($row, true)) at the top of each loop, and see what's in the file after the process dies. 2) If that didn't help, then systematically remove one field at a time from being added as a node, from top to bottom. When you stop getting the error, you found the culprit. 3) If that still didn't help, start re-adding the fields as nodes, from top to bottom.
Make sure the PHP error-log is fully enabled and see if PHP is complaining about anything else. Also think about dumping the row index and PHP's current memory consumption (memory_get_usage) into that same file.
Good luck. Share your results.
(Vote me up if you like/accept this answer.)
Dustin
精彩评论