[英]wamp server not working? or bad php code
我有這個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.
知道為什么它什么都不輸出嗎?
$num=mysql_numrows($result);
應該
$num=mysql_num_rows($result);
多數民眾贊成在至少1個問題。
您還應該研究mysql_fetch_assoc ...
# this will loop through each record
while($row = mysql_fetch_assoc($result)) {
$data = $row['data'];
$sum = $row['suma'];
....
}
我已經多次遇到此錯誤,對我來說,解決方案是增加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。 使用一種適合您的平台,或一一嘗試,直到它起作用為止(就像我所做的那樣)。
您需要啟用錯誤報告以查看發生了什么...編輯php.ini,並設置error_reporting=2147483647
和display_errors=1
。 然后再次運行腳本以檢查所有錯誤...
在日志片段中,某種原因殺死了處理該請求的Apache子級,從而導致TCP連接立即關閉,您的瀏覽器將其視為“連接重置”。
您可能要調查使用“ localhost”而不是“ 127.0.0.1”進行數據庫連接。 MySQL將“ localhost”與IP地址區別對待,並嘗試通過套接字而不是TCP連接進行連接-這是一種速度優化,因為本地套接字比TCP套接字快。 您的MySQL安裝可能未在偵聽TCP連接(skip_networking = 1)。
同樣,絕對不要以root帳戶連接到數據庫,尤其是在這是一個面向公眾的站點時。 根帳戶可以訪問任何內容並在MySQL中執行任何操作,這不是您要公開的內容。 閱讀有關GRANT
語法的信息,並創建一個具有有限特權的MySQL帳戶,然后改用該帳戶。 您的網站很可能只需要插入/更新/選擇/刪除。
除此之外,更改查詢提取邏輯以使用Lizard上面建議的內容,然后開始進行一些調試-找出導致錯誤的行以及到達該錯誤所需的迭代次數。 您可能正在耗盡某種資源,這些資源會殺死Apache / PHP。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.