user426132
user426132

Reputation: 1441

wamp server not working? or bad php code

I have this PHP code:

<?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?

Upvotes: 0

Views: 1279

Answers (4)

PunchyRascal
PunchyRascal

Reputation: 350

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. You will need the Visual studio to do that, but you can use the trial version, as I did. 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. Use the one suitable for you platform or try them one by one, until it works (as I did).

Upvotes: 0

Marc B
Marc B

Reputation: 360572

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

You may want to investigate using 'localhost' instead of '127.0.0.1' for your database connection. 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. Your MySQL install may not be listening for TCP connections (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. The root account can access anything and do anything in MySQL, which is NOT what you want to expose to the world. Read up on the GRANT syntax and create a MySQL account with limited privileges and use that instead. 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. You may be exhausting some kind of resource which kills Apache/PHP.

Upvotes: 0

ircmaxell
ircmaxell

Reputation: 165191

You need to enable error reporting to see what's going on... Edit php.ini, and set error_reporting=2147483647 and display_errors=1. Then run the script again to check for all errors...

Upvotes: 0

Lizard
Lizard

Reputation: 44992

$num=mysql_numrows($result);

should be

$num=mysql_num_rows($result);

Thats atleast 1 issue.

You should also look into mysql_fetch_assoc...

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

Upvotes: 2

Related Questions