Problem with mysqli_fetch_assoc()
Posted: Thu Dec 25, 2008 3:25 pm
Hi. I have a problem with mysqli_fetch_assoc() function (line 20). The full code is:
The error message says something like: 'Apache HTTP server has encountered a problem and needs to close. .. Connection Interrupted. The document contains no data. The network link was interrupted while negotiating a connection. Please try again.'
However, when I replace fetch_assoc with fetch_row, everything works just fine.
PHP version 5.2.8, Apache 2.2.11, MySQL 5.1.
Corresponding Apache error log entries:
[Fri Dec 26 07:45:53 2008] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Fri Dec 26 07:45:55 2008] [notice] Apache/2.2.11 (Win32) PHP/5.2.8 mod_ssl/2.2.11 OpenSSL/0.9.8i configured -- resuming normal operations
[Fri Dec 26 07:45:55 2008] [notice] Server built: Dec 10 2008 00:10:06
[Fri Dec 26 07:45:55 2008] [notice] Parent: Created child process 6116
[Fri Dec 26 07:45:55 2008] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Fri Dec 26 07:45:56 2008] [notice] Child 6116: Child process is running
[Fri Dec 26 07:45:56 2008] [notice] Child 6116: Acquired the start mutex.
[Fri Dec 26 07:45:56 2008] [notice] Child 6116: Starting 64 worker threads.
[Fri Dec 26 07:45:56 2008] [notice] Child 6116: Starting thread to listen on port 80.
Does anyone have any idea what causes this problem?
Code: Select all
<?php
$searchtype=addslashes($_POST['searchtype']);
$searchterm=trim(addslashes($_POST['searchterm']));
if(!$searchtype || !$searchterm)
{
echo "<b><h2>Wrong search conditions entered. Please go back and try again.</h2></b>";
}
@$db=new mysqli("localhost", "bookorama", "bookorama123", "books");
if(mysqli_connect_errno())
{
echo 'Connection to database failed. Please try again later.';
exit;
}
$query="select * from books where ".$searchtype." like '%".$searchterm."%'";
$result=$db->query($query);
$num_results=$result->num_rows;
echo "<font color='green' size=4>Number of books found: ".$num_results.". </font><br/><br/>";
for($i=1; $i<=$num_results; $i++)
{
$row=$result->fetch_assoc();
echo "<b>".$i.". Title: ".htmlspecialchars(stripslashes($row['title']));
echo "</b><br/>Author: ".stripslashes($row['author']);
echo "<br/>ISBN: ".stripslashes($row['isbn']);
echo "<br/>Price: £".stripslashes($row['price']);
echo "<br/><br/>";
}
$result->free();
$db->close();
?>However, when I replace fetch_assoc with fetch_row, everything works just fine.
PHP version 5.2.8, Apache 2.2.11, MySQL 5.1.
Corresponding Apache error log entries:
[Fri Dec 26 07:45:53 2008] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Fri Dec 26 07:45:55 2008] [notice] Apache/2.2.11 (Win32) PHP/5.2.8 mod_ssl/2.2.11 OpenSSL/0.9.8i configured -- resuming normal operations
[Fri Dec 26 07:45:55 2008] [notice] Server built: Dec 10 2008 00:10:06
[Fri Dec 26 07:45:55 2008] [notice] Parent: Created child process 6116
[Fri Dec 26 07:45:55 2008] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Fri Dec 26 07:45:56 2008] [notice] Child 6116: Child process is running
[Fri Dec 26 07:45:56 2008] [notice] Child 6116: Acquired the start mutex.
[Fri Dec 26 07:45:56 2008] [notice] Child 6116: Starting 64 worker threads.
[Fri Dec 26 07:45:56 2008] [notice] Child 6116: Starting thread to listen on port 80.
Does anyone have any idea what causes this problem?