2010-06-15 108 views
0

我有這樣的PHP代碼:wamp服務器不工作?或壞的PHP代碼

<?php 
     $username="root"; 
     $password="******";// censored out 
     $database="bazadedate"; 
     mysql_connect("127.0.0.1",$username,$password); // i get unknown constant localhost if used instead of the loopback ip 
     @mysql_select_db($database) or die("Unable to select database"); 
     $query="SELECT * FROM backup"; 
     $result=mysql_query($query); 
     $num=mysql_numrows($result); 

     $i=0; 
     $raspuns=""; 
      while ($i < $num) { 
      $data=mysql_result($result,$i,"data"); 
      $suma=mysql_result($result,$i,"suma"); 
      $cv=mysql_result($result,$i,"cv"); 
      $det=mysql_result($result,$i,"detaliu"); 

      $raspuns = $raspuns."#".$data."#".$suma."#".$cv."#".$det."@"; 

      $i++; 
      } 

      echo "<b> $raspuns </b>"; 

     mysql_close(); 
?> 

它應該返回一個包含表中的所有數據的單一字符串。但它說「加載頁面時連接重置」。

日誌是:

[Tue Jun 15 16:20:31 2010] [notice] Parent: child process exited with status 255 -- Restarting. 
[Tue Jun 15 16:20:31 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations 
[Tue Jun 15 16:20:31 2010] [notice] Server built: Dec 10 2008 00:10:06 
[Tue Jun 15 16:20:31 2010] [notice] Parent: Created child process 2336 
[Tue Jun 15 16:20:31 2010] [notice] Child 2336: Child process is running 
[Tue Jun 15 16:20:31 2010] [notice] Child 2336: Acquired the start mutex. 
[Tue Jun 15 16:20:31 2010] [notice] Child 2336: Starting 64 worker threads. 
[Tue Jun 15 16:20:31 2010] [notice] Child 2336: Starting thread to listen on port 80. 
[Tue Jun 15 16:20:35 2010] [notice] Parent: child process exited with status 255 -- Restarting. 
[Tue Jun 15 16:20:35 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations 
[Tue Jun 15 16:20:35 2010] [notice] Server built: Dec 10 2008 00:10:06 
[Tue Jun 15 16:20:35 2010] [notice] Parent: Created child process 1928 
[Tue Jun 15 16:20:35 2010] [notice] Child 1928: Child process is running 
[Tue Jun 15 16:20:35 2010] [notice] Child 1928: Acquired the start mutex. 
[Tue Jun 15 16:20:35 2010] [notice] Child 1928: Starting 64 worker threads. 
[Tue Jun 15 16:20:35 2010] [notice] Child 1928: Starting thread to listen on port 80. 

任何想法,爲什麼它什麼也不輸出?

回答

2
$num=mysql_numrows($result); 

應該

$num=mysql_num_rows($result); 

那ATLEAST 1點的問題。

你也應該看看mysql_fetch_assoc ...

# this will loop through each record 
while($row = mysql_fetch_assoc($result)) { 
    $data = $row['data']; 
    $sum = $row['suma']; 
    .... 
} 
0

您需要啓用error reporting,看看發生了什麼事情...編輯php.ini文件,並設置error_reporting=2147483647display_errors=1。然後再次運行該腳本以檢查所有錯誤...

0

從日誌片段中,某些內容正在處理請求,導致TCP連接立即關閉,您的瀏覽器將其視爲「Connection reset 」。

您可能想要爲您的數據庫連接使用'localhost'而不是'127.0.0.1'進行調查。 MySQL將「localhost」視爲不同於IP地址,並嘗試通過套接字而不是TCP連接進行連接 - 這是速度優化,因爲本地套接字比TCP套接字快。您的MySQL安裝可能不會偵聽TCP連接(skip_networking = 1)。

同樣,你永遠不應該連接到你的數據庫作爲根帳戶,特別是如果這將是一個面向公衆的網站。 root帳戶可以訪問任何內容並在MySQL中執行任何操作,這不是您想要公開給世界的內容。請閱讀GRANT syntax並創建一個具有有限權限的MySQL帳戶,然後使用它。很可能你的網站只需要插入/更新/選擇/刪除。

除此之外,更改您的查詢獲取邏輯,以使用上面提到的Lizard,並開始進行一些調試 - 找出導致錯誤的哪一行以及需要多少次迭代才能實現。你可能會耗盡某些殺死Apache/PHP的資源。

0

我已經多次遇到這個錯誤,對我來說,解決方案是增加apache二進制文件(apache.exe或httpd.exe)堆棧大小。你需要Visual Studio來做到這一點,但你可以像我一樣使用試用版。你甚至不需要打開它。命令是:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64>editbin /STACK:8000000 "c:\Program Files (x86)\WAMP\apache\bin\apache.exe" 

當然根據你的環境改變路徑。

在Visual Studio目錄中,VC/binary /有幾個實用程序,名稱爲editbin.exe。使用適合你的平臺或者一個一個地嘗試,直到它工作(像我一樣)。