ID: 48453
User updated by: gubbov53 at hotmail dot com
Reported By: gubbov53 at hotmail dot com
-Status: Feedback
+Status: Open
Bug Type: mSQL related
Operating System: Vista
PHP Version: 5.2.9
New Comment:
To have this problem set up a small MySQL db by running the following
as root:
------------
create database books_db;
use books_db;
create table books
( isbn char(13) not null primary key,
author char(50),
title char(100),
price float(4,2)
);
grant select, insert, update, delete
on books_db.*
to books_u...@localhost identified by 'password';
insert into books values
("0-672-31697-8", "Michael Morgan", "Java 2 for Professional
Developers", 34.99),
("0-672-31745-1", "Thomas Down", "Installing Debian GNU/Linux",
24.99);
---------------
Then run this file in IE:
--------------
<html>
<body>
<?php
@ $db=new mysqli('localhost','books_user','password','books_db');
if (mysqli_connect_errno()) {
echo "Error: Could not connect to database. Please try again
later.";
exit;
}
$query="select title,author from books where author like
'%Morgan%'";
$result=$db->query($query);
$num_results=$result->num_rows;
echo "<p>Number of books found: ".$num_results."</p>";
for ($i=0; $i<$num_results; $i++) {
$row=$result->fetch_assoc(); // loops here...
echo "<p><strong>".($i+1)." Title: ";
echo htmlspecialchars(stripslashes($row['title']));
echo "</strong><br />Author: ";
echo stripslashes($row['author']);
}
$result->free();
$db->close();
?>
</body>
</html>
Previous Comments:
------------------------------------------------------------------------
[2009-06-02 20:09:18] [email protected]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
------------------------------------------------------------------------
[2009-06-02 15:13:12] gubbov53 at hotmail dot com
Description:
------------
fetch_assoc() (see below) does not work. Hangs Apache.
If "$row=$result->fetch_assoc();" is replaced by
"$row=$result->fetch_row();" the code is working...
Reproduce code:
---------------
$result=$db->query($query);
$num_results=$result->num_rows;
echo "<p>Number of books found: ".$num_results."</p>";
for ($i=0; $i<$num_results; $i++) {
$row=$result->fetch_assoc(); // Does not work!!!
...
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48453&edit=1