简体   繁体   English

沼泽服务器不工作? 或错误的php代码

[英]wamp server not working? or bad php code

I have this 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();
?>

And it should return a single string containing all data from the table. 并且它应该返回一个包含表中所有数据的字符串。 But it says "connection reset when loading page". 但是它说“加载页面时重置连接”。

the log is : 日志是:

[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.

Any idea why it outputs nothing? 知道为什么它什么都不输出吗?

$num=mysql_numrows($result);

should be 应该

$num=mysql_num_rows($result);

Thats atleast 1 issue. 多数民众赞成在至少1个问题。

You should also look into mysql_fetch_assoc... 您还应该研究mysql_fetch_assoc ...

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

I have experienced this error many times and the solution for me was to increase the apache binary (apache.exe or httpd.exe) stack size. 我已经多次遇到此错误,对我来说,解决方案是增加apache二进制文件(apache.exe或httpd.exe)的堆栈大小。 You will need the Visual studio to do that, but you can use the trial version, as I did. 您将需要Visual Studio来执行此操作,但是可以像我一样使用试用版。 You don't even need to turn it on. 您甚至不需要打开它。 The command is: 命令是:

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

Change the paths above according to your environment of course. 当然,请根据您的环境更改上述路径。

In the Visual studio directory VC/binary/ there are several utilities by the name editbin.exe. 在Visual Studio目录VC / binary /中,有几个实用程序,名称为editbin.exe。 Use the one suitable for you platform or try them one by one, until it works (as I did). 使用一种适合您的平台,或一一尝试,直到它起作用为止(就像我所做的那样)。

You need to enable error reporting to see what's going on... Edit php.ini, and set error_reporting=2147483647 and display_errors=1 . 您需要启用错误报告以查看发生了什么...编辑php.ini,并设置error_reporting=2147483647display_errors=1 Then run the script again to check for all errors... 然后再次运行脚本以检查所有错误...

From the log snippet, something's killing the Apache child handling the request, which causes an immediate shutdown of the TCP connection, which your browser sees as a "Connection reset". 在日志片段中,某种原因杀死了处理该请求的Apache子级,从而导致TCP连接立即关闭,您的浏览器将其视为“连接重置”。

You may want to investigate using 'localhost' instead of '127.0.0.1' for your database connection. 您可能要调查使用“ localhost”而不是“ 127.0.0.1”进行数据库连接。 MySQL treats "localhost" differently than an IP address, and tries to connect via sockets, rather than a TCP connection - this is a speed optimization as local sockets are faster than TCP sockets. MySQL将“ localhost”与IP地址区别对待,并尝试通过套接字而不是TCP连接进行连接-这是一种速度优化,因为本地套接字比TCP套接字快。 Your MySQL install may not be listening for TCP connections (skip_networking = 1). 您的MySQL安装可能未在侦听TCP连接(skip_networking = 1)。

As well, you should NEVER connect to your database as the root account, especially if this will be a public-facing site. 同样,绝对不要以root帐户连接到数据库,尤其是在这是一个面向公众的站点时。 The root account can access anything and do anything in MySQL, which is NOT what you want to expose to the world. 根帐户可以访问任何内容并在MySQL中执行任何操作,这不是您要公开的内容。 Read up on the GRANT syntax and create a MySQL account with limited privileges and use that instead. 阅读有关GRANT语法的信息,并创建一个具有有限特权的MySQL帐户,然后改用该帐户。 Most likely your site would only need insert/update/select/delete. 您的网站很可能只需要插入/更新/选择/删除。

Beyond that, change your query fetching logic to use what Lizard suggested above, and start doing some debugging - figure out which line is causing the error, and how many iterations it took to get there. 除此之外,更改查询提取逻辑以使用Lizard上面建议的内容,然后开始进行一些调试-找出导致错误的行以及到达该错误所需的迭代次数。 You may be exhausting some kind of resource which kills Apache/PHP. 您可能正在耗尽某种资源,这些资源会杀死Apache / PHP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM