2011-09-05 91 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)轉儲到同一個文件中。

祝你好運。分享您的結果。

(如果你喜歡/接受這個答案投票給我。)

達斯汀

相關問題