
|
Apache crashes when using WHILE loop to traverse SQL query results
Hi,
I have set up an environment on my Vista laptop comprising of Apache 2.2, MySQL Server 5.1 and Php 5.2.5.
I'm using a simple php program that I found in a PHP/SQL book. The PHP program queries a MySQL table and uses a WHILE loop to traverse the results array of the query and display on screen. However, there seems to be a problem with my environment and using a WHILE loop as every time I run the program I get the error "Apache HTTP server stopped working and was closed".
I have no problems using a FOR loop but every time I use a WHILE loop Apache seems to crash. Please see below for the code I have used.
I would be extremely for any suggestions of why this is happening and any solutions offered.
Thanks.
<?php /* Program: petDisplay.php * Desc: Displays all pets in selected category. */
?> <html> <head><title>Pet Catalog</title></head> <body> <?php $user="root"; $host="localhost"; $password="PASSWORD";
$database = "am"; $cxn = mysqli_connect($host,$user,$password,$database) or die ("couldn't connect to server"); $pettype = "horse"; //horse was typed in a form by user
$query = "SELECT * FROM Pet WHERE petType='$pettype'"; $result = mysqli_query($cxn,$query) or die ("Couldn't execute query."); /*Display results in a table */
$pettype = ucfirst($pettype)."s"; echo "<h1>$pettype</h1>"; echo "<table cellspacing='15'>"; echo "<tr><td colspan='3'><hr /></td></tr>";
while($row = mysqli_fetch_assoc($result)) { extract($row); $f_price = number_format($price,2); echo "<tr>\n <td>$petName</td>\n <td>$petDescription</td>\n
<td style='text-align: right'>\$$f_price</td>\n </tr>\n"; echo "<tr><td colspan='3'><hr /></td></tr>\n";
} echo "</table>\n"; ?> </body></html>
|

|
Fwd: Apache crashes when using WHILE loop to traverse SQL query results
Also, please see messages I have copied from the Apache error log:
[Sun Jul 06 09:38:30 2008] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Sun Jul 06 09:38:30 2008] [notice] Apache/2.2.6 (Win32) PHP/5.2.4 configured -- resuming normal operations [Sun Jul 06 09:38:30 2008] [notice] Server built: Sep 5 2007 08:58:56 [Sun Jul 06 09:38:30 2008] [notice] Parent: Created child process 4372
[Sun Jul 06 09:38:31 2008] [notice] Child 4372: Child process is running [Sun Jul 06 09:38:31 2008] [notice] Child 4372: Acquired the start mutex. [Sun Jul 06 09:38:31 2008] [notice] Child 4372: Starting 250 worker threads.
[Sun Jul 06 09:38:31 2008] [notice] Child 4372: Starting thread to listen on port 80.
Any help would be much apprecieted.
Thanks,
Bonger
---------- Forwarded message ---------- From: Bonger O < bongero@...> Date: Sat, Jul 5, 2008 at 6:55 PM
Subject: Apache crashes when using WHILE loop to traverse SQL query results To: users@...
Hi,
I have set up an environment on my Vista laptop comprising of Apache 2.2, MySQL Server 5.1 and Php 5.2.5.
I'm using a simple php program that I found in a PHP/SQL book. The PHP program queries a MySQL table and uses a WHILE loop to traverse the results array of the query and display on screen. However, there seems to be a problem with my environment and using a WHILE loop as every time I run the program I get the error "Apache HTTP server stopped working and was closed".
I have no problems using a FOR loop but every time I use a WHILE loop Apache seems to crash. Please see below for the code I have used.
I would be extremely for any suggestions of why this is happening and any solutions offered.
Thanks.
<?php /* Program: petDisplay.php * Desc: Displays all pets in selected category. */
?> <html> <head><title>Pet Catalog</title></head> <body> <?php $user="root"; $host="localhost"; $password="PASSWORD";
$database = "am"; $cxn = mysqli_connect($host,$user,$password,$database) or die ("couldn't connect to server"); $pettype = "horse"; //horse was typed in a form by user
$query = "SELECT * FROM Pet WHERE petType='$pettype'"; $result = mysqli_query($cxn,$query) or die ("Couldn't execute query."); /*Display results in a table */
$pettype = ucfirst($pettype)."s"; echo "<h1>$pettype</h1>"; echo "<table cellspacing='15'>"; echo "<tr><td colspan='3'><hr /></td></tr>";
while($row = mysqli_fetch_assoc($result)) { extract($row); $f_price = number_format($price,2); echo "<tr>\n <td>$petName</td>\n <td>$petDescription</td>\n
<td style='text-align: right'>\$$f_price</td>\n </tr>\n"; echo "<tr><td colspan='3'><hr /></td></tr>\n";
} echo "</table>\n"; ?> </body></html>
|

|
Re: Apache crashes when using WHILE loop to traverse SQL query results
With php when you include vars in double quotes don't you want to put
curly braces around them like so?
$query = "SELECT * FROM Pet WHERE petType='{$pettype}'";
That's how I do it but I've been doing it so long I don't remember why.
Anyway, I would guess this is a php issue and not an apache problem.
Turn up your php error reporting. Off the top of my head something
like this at the top of your script.
error_reporting(E_ALL);
php.net is your friend:
http://php.net/whilehttp://php.net/error_reporting//brad
On Jul 5, 2008, at 10:55 AM, Bonger O wrote:
> Hi,
>
> I have set up an environment on my Vista laptop comprising of Apache
> 2.2, MySQL Server 5.1 and Php 5.2.5.
>
> I'm using a simple php program that I found in a PHP/SQL book. The
> PHP program queries a MySQL table and uses a WHILE loop to traverse
> the results array of the query and display on screen. However, there
> seems to be a problem with my environment and using a WHILE loop as
> every time I run the program I get the error "Apache HTTP server
> stopped working and was closed".
>
> I have no problems using a FOR loop but every time I use a WHILE
> loop Apache seems to crash. Please see below for the code I have used.
>
> I would be extremely for any suggestions of why this is happening
> and any solutions offered.
>
> Thanks.
>
> <?php
> /* Program: petDisplay.php
> * Desc: Displays all pets in selected category.
> */
> ?>
> <html>
> <head><title>Pet Catalog</title></head>
> <body>
> <?php
>
> $user="root";
> $host="localhost";
> $password="PASSWORD";
> $database = "am";
> $cxn = mysqli_connect($host,$user,$password,$database)
> or die ("couldn't connect to server");
> $pettype = "horse"; //horse was typed in a form by user
> $query = "SELECT * FROM Pet WHERE petType='$pettype'";
> $result = mysqli_query($cxn,$query)
> or die ("Couldn't execute query.");
>
> /*Display results in a table */
> $pettype = ucfirst($pettype)."s";
>
> echo "<h1>$pettype</h1>";
> echo "<table cellspacing='15'>";
> echo "<tr><td colspan='3'><hr /></td></tr>";
> while($row = mysqli_fetch_assoc($result))
> {
> extract($row);
>
> $f_price = number_format($price,2);
> echo "<tr>\n
> <td>$petName</td>\n
> <td>$petDescription</td>\n
> <td style='text-align: right'>\$$f_price</td>\n
> </tr>\n";
> echo "<tr><td colspan='3'><hr /></td></tr>\n";
> }
> echo "</table>\n";
> ?>
> </body></html>
>
>
>
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL: http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@...
" from the digest: users-digest-unsubscribe@...
For additional commands, e-mail: users-help@...
|

|
Re: Apache crashes when using WHILE loop to traverse SQL query results
Bonger, Are you using Apache with the Worker MPM? If so, that could be your problem. It is fairly well documented and highly discussed that the Worker MPM on *nix is not a good combination, as explained here: http://us2.php.net/manual/en/faq.installation.php#faq.installation.apache2. The problem is not the PHP core itself, but the third-party libraries that may not be thread-safe. According to the link above, this is of much less concern to those using Windows. But perhaps it's worth a try to switch to the Prefork MPM and see if the symtpoms disappear.
Cheers, Rich On Sun, Jul 6, 2008 at 9:31 AM, Bradley Giesbrecht < brad@...> wrote:
With php when you include vars in double quotes don't you want to put curly braces around them like so?
$query = "SELECT * FROM Pet WHERE petType='{$pettype}'";
That's how I do it but I've been doing it so long I don't remember why.
Anyway, I would guess this is a php issue and not an apache problem.
Turn up your php error reporting. Off the top of my head something like this at the top of your script.
error_reporting(E_ALL);
php.net is your friend:
http://php.net/while
http://php.net/error_reporting
//brad
On Jul 5, 2008, at 10:55 AM, Bonger O wrote:
Hi,
I have set up an environment on my Vista laptop comprising of Apache 2.2, MySQL Server 5.1 and Php 5.2.5.
I'm using a simple php program that I found in a PHP/SQL book. The PHP program queries a MySQL table and uses a WHILE loop to traverse the results array of the query and display on screen. However, there seems to be a problem with my environment and using a WHILE loop as every time I run the program I get the error "Apache HTTP server stopped working and was closed".
I have no problems using a FOR loop but every time I use a WHILE loop Apache seems to crash. Please see below for the code I have used.
I would be extremely for any suggestions of why this is happening and any solutions offered.
Thanks.
<?php
/* Program: petDisplay.php
* Desc: Displays all pets in selected category.
*/
?>
<html>
<head><title>Pet Catalog</title></head>
<body>
<?php
$user="root";
$host="localhost";
$password="PASSWORD";
$database = "am";
$cxn = mysqli_connect($host,$user,$password,$database)
or die ("couldn't connect to server");
$pettype = "horse"; //horse was typed in a form by user
$query = "SELECT * FROM Pet WHERE petType='$pettype'";
$result = mysqli_query($cxn,$query)
or die ("Couldn't execute query.");
/*Display results in a table */
$pettype = ucfirst($pettype)."s";
echo "<h1>$pettype</h1>";
echo "<table cellspacing='15'>";
echo "<tr><td colspan='3'><hr /></td></tr>";
while($row = mysqli_fetch_assoc($result))
{
extract($row);
$f_price = number_format($price,2);
echo "<tr>\n
<td>$petName</td>\n
<td>$petDescription</td>\n
<td style='text-align: right'>\$$f_price</td>\n
</tr>\n";
echo "<tr><td colspan='3'><hr /></td></tr>\n";
}
echo "</table>\n";
?>
</body></html>
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@...
" from the digest: users-digest-unsubscribe@...
For additional commands, e-mail: users-help@...
|

|
Re: Apache crashes when using WHILE loop to traverse SQL query results
Hi guys,
Thanks for getting back to me on this with your comments, but sadly I've still had no luck.
I have managed to narrow the problem down to $row = mysqli_fetch_assoc($result);
For some reason this is causing the crash. Would there be any reason that this function cant be found perhaps? I really have no clue!!!
On Mon, Jul 7, 2008 at 6:39 PM, Rich Schumacher < rich.schu@...> wrote:
Bonger,
Are you using Apache with the Worker MPM? If so, that could be your problem. It is fairly well documented and highly discussed that the Worker MPM on *nix is not a good combination, as explained here: http://us2.php.net/manual/en/faq.installation.php#faq.installation.apache2. The problem is not the PHP core itself, but the third-party libraries that may not be thread-safe. According to the link above, this is of much less concern to those using Windows. But perhaps it's worth a try to switch to the Prefork MPM and see if the symtpoms disappear.
Cheers,
Rich
On Sun, Jul 6, 2008 at 9:31 AM, Bradley Giesbrecht < brad@...> wrote:
With php when you include vars in double quotes don't you want to put curly braces around them like so?
$query = "SELECT * FROM Pet WHERE petType='{$pettype}'";
That's how I do it but I've been doing it so long I don't remember why.
Anyway, I would guess this is a php issue and not an apache problem.
Turn up your php error reporting. Off the top of my head something like this at the top of your script.
error_reporting(E_ALL);
php.net is your friend:
http://php.net/while
http://php.net/error_reporting
//brad
On Jul 5, 2008, at 10:55 AM, Bonger O wrote:
Hi,
I have set up an environment on my Vista laptop comprising of Apache 2.2, MySQL Server 5.1 and Php 5.2.5.
I'm using a simple php program that I found in a PHP/SQL book. The PHP program queries a MySQL table and uses a WHILE loop to traverse the results array of the query and display on screen. However, there seems to be a problem with my environment and using a WHILE loop as every time I run the program I get the error "Apache HTTP server stopped working and was closed".
I have no problems using a FOR loop but every time I use a WHILE loop Apache seems to crash. Please see below for the code I have used.
I would be extremely for any suggestions of why this is happening and any solutions offered.
Thanks.
<?php /* Program: petDisplay.php * Desc: Displays all pets in selected category. */ ?> <html> <head><title>Pet Catalog</title></head> <body>
<?php
$user="root"; $host="localhost"; $password="PASSWORD"; $database = "am"; $cxn = mysqli_connect($host,$user,$password,$database) or die ("couldn't connect to server");
$pettype = "horse"; //horse was typed in a form by user $query = "SELECT * FROM Pet WHERE petType='$pettype'"; $result = mysqli_query($cxn,$query) or die ("Couldn't execute query.");
/*Display results in a table */ $pettype = ucfirst($pettype)."s";
echo "<h1>$pettype</h1>"; echo "<table cellspacing='15'>"; echo "<tr><td colspan='3'><hr /></td></tr>";
while($row = mysqli_fetch_assoc($result)) { extract($row);
$f_price = number_format($price,2); echo "<tr>\n <td>$petName</td>\n <td>$petDescription</td>\n
<td style='text-align: right'>\$$f_price</td>\n </tr>\n"; echo "<tr><td colspan='3'><hr /></td></tr>\n"; }
echo "</table>\n"; ?> </body></html>
--------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info. To unsubscribe, e-mail: users-unsubscribe@...
" from the digest: users-digest-unsubscribe@... For additional commands, e-mail: users-help@...
|

|
Re: Apache crashes when using WHILE loop to traverse SQL query results
Note: This is turning more into a PHP issue than Apache... You must have the MySQLi extension already installed, otherwise it would complain about mysqli_connect() being an invalid function. Do you have command line access? If so, try running the script above from the command line to see if that produces anything different.
Cheers, Rich On Mon, Jul 7, 2008 at 3:05 PM, Bonger O < bongero@...> wrote:
Hi guys,
Thanks for getting back to me on this with your comments, but sadly I've still had no luck.
I have managed to narrow the problem down to $row = mysqli_fetch_assoc($result);
For some reason this is causing the crash. Would there be any reason that this function cant be found perhaps? I really have no clue!!!
On Mon, Jul 7, 2008 at 6:39 PM, Rich Schumacher < rich.schu@...> wrote:
Bonger,
Are you using Apache with the Worker MPM? If so, that could be your problem. It is fairly well documented and highly discussed that the Worker MPM on *nix is not a good combination, as explained here: http://us2.php.net/manual/en/faq.installation.php#faq.installation.apache2. The problem is not the PHP core itself, but the third-party libraries that may not be thread-safe. According to the link above, this is of much less concern to those using Windows. But perhaps it's worth a try to switch to the Prefork MPM and see if the symtpoms disappear.
Cheers,
Rich
On Sun, Jul 6, 2008 at 9:31 AM, Bradley Giesbrecht < brad@...> wrote:
With php when you include vars in double quotes don't you want to put curly braces around them like so?
$query = "SELECT * FROM Pet WHERE petType='{$pettype}'";
That's how I do it but I've been doing it so long I don't remember why.
Anyway, I would guess this is a php issue and not an apache problem.
Turn up your php error reporting. Off the top of my head something like this at the top of your script.
error_reporting(E_ALL);
php.net is your friend:
http://php.net/while
http://php.net/error_reporting
//brad
On Jul 5, 2008, at 10:55 AM, Bonger O wrote:
Hi,
I have set up an environment on my Vista laptop comprising of Apache 2.2, MySQL Server 5.1 and Php 5.2.5.
I'm using a simple php program that I found in a PHP/SQL book. The PHP program queries a MySQL table and uses a WHILE loop to traverse the results array of the query and display on screen. However, there seems to be a problem with my environment and using a WHILE loop as every time I run the program I get the error "Apache HTTP server stopped working and was closed".
I have no problems using a FOR loop but every time I use a WHILE loop Apache seems to crash. Please see below for the code I have used.
I would be extremely for any suggestions of why this is happening and any solutions offered.
Thanks.
<?php /* Program: petDisplay.php * Desc: Displays all pets in selected category. */ ?> <html> <head><title>Pet Catalog</title></head> <body>
<?php
$user="root"; $host="localhost"; $password="PASSWORD"; $database = "am"; $cxn = mysqli_connect($host,$user,$password,$database) or die ("couldn't connect to server");
$pettype = "horse"; //horse was typed in a form by user $query = "SELECT * FROM Pet WHERE petType='$pettype'"; $result = mysqli_query($cxn,$query) or die ("Couldn't execute query.");
/*Display results in a table */ $pettype = ucfirst($pettype)."s";
echo "<h1>$pettype</h1>"; echo "<table cellspacing='15'>"; echo "<tr><td colspan='3'><hr /></td></tr>";
while($row = mysqli_fetch_assoc($result)) { extract($row);
$f_price = number_format($price,2); echo "<tr>\n <td>$petName</td>\n <td>$petDescription</td>\n
<td style='text-align: right'>\$$f_price</td>\n </tr>\n"; echo "<tr><td colspan='3'><hr /></td></tr>\n"; }
echo "</table>\n"; ?> </body></html>
--------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info. To unsubscribe, e-mail: users-unsubscribe@...
" from the digest: users-digest-unsubscribe@... For additional commands, e-mail: users-help@...
|

|
Re: Apache crashes when using WHILE loop to traverse SQL query results
Bonger O wrote:
> Hi guys,
>
> Thanks for getting back to me on this with your comments, but sadly
> I've still had no luck.
>
> I have managed to narrow the problem down to *$row =
> mysqli_fetch_assoc($result);*
> For some reason this is causing the crash. Would there be any reason
> that this function cant be found perhaps? I really have no clue!!!
>
>
>
It would probably crash (or throw errors) if $result was empty.
Probably need to move this to a PHP newsgroup.
--
Norman
Registered Linux user #461062
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL: http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@...
" from the digest: users-digest-unsubscribe@...
For additional commands, e-mail: users-help@...
|

|
Re: Apache crashes when using WHILE loop to traverse SQL query results
Thanks for the advice guys. I'll go pester some PHP folks!
On Tue, Jul 8, 2008 at 12:26 PM, Norman Peelman < npeelman@...> wrote:
Bonger O wrote:
Hi guys, Thanks for getting back to me on this with your comments, but sadly I've still had no luck.
I have managed to narrow the problem down to *$row = mysqli_fetch_assoc($result);* For some reason this is causing the crash. Would there be any reason that this function cant be found perhaps? I really have no clue!!!
It would probably crash (or throw errors) if $result was empty. Probably need to move this to a PHP newsgroup.
-- Norman Registered Linux user #461062
|