2011-09-05 93 views
2

我在写一个查询时遇到了一些问题(请参阅下文)。堆栈空间不足错误

<?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 = 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(); 

?> 

当我通过我的网页浏览器上运行PHP脚本它检索正确的数据,但是当我通过HTML页面运行此我得到一个“的堆栈”的错误。从我在网上阅读的内容来看,我认为这可能是因为SQL查询太复杂了。

你能告诉我一个过于复杂的SQL查询会导致这种类型的错误吗?

+4

PHP是一个服务器端语言,所以我想不通“通过Web浏览器”,什么“虽然HTML页面“是指在这种情况下,它们有何不同。 –

+0

查询绝对不是太复杂。你的代码一次只处理一行,你每次获取的数据量是有限的。 – Johan

+0

嗨,非常感谢回复我的帖子。我明白,PHP是基于服务器的,但通过使用php文件名并将其输入到Web浏览器的地址框中,您可以看到从“后端”拉取的数据。这与使用html表单作为Web地址明显不同。我希望这是有道理的?亲切的问候Chris – IRHM

回答

1

您的数据出现问题/意外情况。

1)在每个循环的顶部执行file_put_contents(“somedumpfile”,var_export($ row,true)),并查看进程死后的文件内容。 2)如果没有帮助,那么从上到下系统地删除一个字段,作为节点添加。当你不再发生错误时,你找到了罪魁祸首。 3)如果仍然没有帮助,开始重新添加字段作为节点,从上到下。

确保PHP错误日志已完全启用并查看PHP是否在抱怨其他任何内容。同时考虑将行索引和PHP的当前内存消耗(memory_get_usage)转储到同一个文件中。

祝你好运。分享您的结果。

(如果你喜欢/接受这个答案投票给我。)

达斯汀

相关问题