ID: 48453
User updated by: gubbov53 at hotmail dot com
Reported By: gubbov53 at hotmail dot com
Status: Assigned
Bug Type: MySQLi related
Operating System: Windows Vista
PHP Version: 5.2.9
Assigned To: mysql
New Comment:
A temp solution to have it working if you have code with fetch_assoc()
is to replace fetch_assoc() with fetch_fields() (to get keys),
fetch_row() (to get values), and array_combine(). See example below...
<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>";
$finfo = $result->fetch_fields(); $nc=0; foreach ($finfo as $val)
{$row_key[$nc++]=$val->name;} //---
for ($i=0; $i<$num_results; $i++) {
//$row=$result->fetch_assoc();
$row_val=$result->fetch_row();$row=array_combine($row_key,$row_val);
//---
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-06 08:06:54] jacobus0223 at hotmail dot com
I have this problem too and also have the same problem with
fetch_object(). The browser hangs and finally times out.
I also note that there was a problem with these same two functions back
in 2002 -- http://bugs.php.net/bug.php?id=18622.
------------------------------------------------------------------------
[2009-06-04 08:44:18] [email protected]
There is a script to test.
------------------------------------------------------------------------
[2009-06-04 08:41:15] gubbov53 at hotmail dot com
Tried with the latest PHP Version 5.2.10RC2-dev but the problem
remains.
------------------------------------------------------------------------
[2009-06-03 20:39:54] [email protected]
Please read this: http://bugs.php.net/how-to-report.php
------------------------------------------------------------------------
[2009-06-03 12:48:40] gubbov53 at hotmail dot com
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>
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/48453
--
Edit this bug report at http://bugs.php.net/?id=48453&edit=1