Bug #48453 [Fbk->NoF]: fetch_assoc() problem
| From: | uw@php.net | Date: | Fri, 04 Nov 2011 10:07:53 +0000 |
| Subject: | Bug #48453 [Fbk->NoF]: fetch_assoc() problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-164873@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=48453&edit=1
ID: 48453
Updated by: uw@php.net
Reported by: gubbov53 at hotmail dot com
Summary: fetch_assoc() problem
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: MySQLi related
Operating System: Windows Vista
PHP Version: 5.2.9
Assigned To: mysql
Block user comment: N
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2010-08-13 11:54:23] andrey@php.net
Can you reproduce this with 5.3?
------------------------------------------------------------------------
[2010-02-01 22:11:04] marco at marcoentertainment dot com
oh yeah i also got a syntax error in my for loop at **** , $i++) which went away when a semicolon
was added ie. $i++;)
i'm pretty tired so i prob missed something but still was odd
------------------------------------------------------------------------
[2010-02-01 22:06:27] marco at marcoentertainment dot com
okay i wrote below with no sucess used the code from gubbov and it works as it should :? when i used
my code it seems like it didnt parse the for loop properly but code after it was executed fine so
ehhh but thanks gubbov
<?php
$link = mysqli_connect(localhost,*******,'******') or die;
mysqli_select_db($link, o******) or die;
if (mysqli_connect_errno()) {
echo 'Error: CNC';
exit;
}
$query = "SELECT a.product_price, b.product_name, b.product_thumb_image, c.category_id,
a.product_id
FROM jos_vm_product_price AS a, jos_vm_product AS b, jos_vm_product_category_xref AS c WHERE
a.product_price >= 100 AND a.product_id = b.product_id AND c.product_id = a.product_id AND
b.product_id = c.product_id AND
b.product_publish = 'Y' ORDER BY a.product_price";
$result = mysqli_query($link, $query);
$num_results = mysqli_num_rows($result);
echo "<p>Number Found: ".$num_results."</p>";
for ($i=0, $i <$num_results; $i++) {
$row = mysqli_fetch_row($result);
echo "<p>".($i+1).". Price: ";
echo ($row['product_price']);
echo "</p>";
}
mysqli_free_result($result);
mysqli_close($link);
?>
------------------------------------------------------------------------
[2009-08-12 14:09:49] mail at maiknowak dot de
php-code:
$sql="SELECT * FROM foo" //causes Windows crash dialog or Apache crash
$sql="SELECT bar, baz FROM foo" //works just fine
$result = $myMysql->query ( $sql );
$row = $result->fetch_assoc();
ver 5.2.10 & 5.3 shipped with Zend Studio 7
------------------------------------------------------------------------
[2009-06-09 19:31:22] gubbov53 at hotmail dot com
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>
------------------------------------------------------------------------
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
https://bugs.php.net/bug.php?id=48453
--
Edit this bug report at https://bugs.php.net/bug.php?id=48453&edit=1