|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-10-03 15:10 UTC] ilantipov at gmail dot com
Description:
------------
mysqli_fetch_assoc($query_id) gives results, but
$row2 = $db->sql_fetchrow($result));
print_r($row2);
does not
Test script:
---------------
I am using phpbb3 while running a query
when I use this code
$query = "SELECT t.forum_id, count(topic_id) AS count_sticky FROM phpbb_topics as t, phpbb_prices_forums as f WHERE t.forum_id=f.forum_id AND f.forum_id IN (509, 545, 25, 45, 543, 20, 35, 487, 223, 288, 224, 256) AND topic_type=1 and topic_sticky_flag > 0 GROUP BY t.forum_id HAVING count_sticky <5";
if ($result = mysqli_query($link, $query)) {
while ($row = mysqli_fetch_row($result)) {
printf ("%s (%s)\n", $row[0], $row[1]);
}
}
I get
256 (4)
543 (1)
Which is ok. But when I'm using this code
$result = $db->sql_query($sql);
while($row2 = $db->sql_fetchrow($result));
{
print($row2);
}
I get nothing. And gettype($row2) gives NULL
$db->sql_fetchrow in minimal configuration to reproduce a bug is:
function sql_fetchrow($query_id = false)
{
return mysqli_fetch_assoc($query_id);
}
If I rewrite my code to
$result = $db->sql_query($sql);
print_r($db->sql_fetchrow($result));
print_r($db->sql_fetchrow($result));
I get
Array
(
[forum_id] => 256
[count_sticky] => 4
)
Array
(
[forum_id] => 543
[count_sticky] => 1
)
The other variant of code:
$result = $db->sql_query($sql);
$row2 = $db->sql_fetchrow($result);
print_r($row2);
$row2 = $db->sql_fetchrow($result);
print_r($row2);
Gives good results as well. It works as acpected.
So the bug occures only in this case - when passing back results to 'while' loop as a result of other function. All other queries work perfect on a production server. And I have the same issues on 2 servers with PHP 5.4.17 and PHP 5.4.20 running.
Any other info can be sent if needed.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 17:00:01 2025 UTC |
Ok. I try to reconstruct it other way $query = "SELECT t.forum_id, count(topic_id) AS count_sticky FROM phpbb_topics as t, phpbb_prices_forums as f WHERE t.forum_id=f.forum_id AND f.forum_id IN (509, 545, 25, 45, 543, 20, 35, 487, 223, 288, 224, 256) AND topic_type=1 and topic_sticky_flag > 0 GROUP BY t.forum_id HAVING count_sticky <5"; $result = mysqli_query($link, $query) ; print_r(mysqli_fetch_assoc($result)); print_r(mysqli_fetch_assoc($result)); gives: Array ( [forum_id] => 256 [count_sticky] => 4 ) Array ( [forum_id] => 543 [count_sticky] => 1 ) this code works as well $query = "SELECT t.forum_id, count(topic_id) AS count_sticky FROM phpbb_topics as t, phpbb_prices_forums as f WHERE t.forum_id=f.forum_id AND f.forum_id IN (509, 545, 25, 45, 543, 20, 35, 487, 223, 288, 224, 256) AND topic_type=1 and topic_sticky_flag > 0 GROUP BY t.forum_id HAVING count_sticky <5"; $result = mysqli_query($link, $query) ; $row2 = mysqli_fetch_assoc($result); print_r($row2); $row2 = mysqli_fetch_assoc($result); print_r($row2); output: Array ( [forum_id] => 256 [count_sticky] => 4 ) Array ( [forum_id] => 543 [count_sticky] => 1 ) BUT $query = "SELECT t.forum_id, count(topic_id) AS count_sticky FROM phpbb_topics as t, phpbb_prices_forums as f WHERE t.forum_id=f.forum_id AND f.forum_id IN (509, 545, 25, 45, 543, 20, 35, 487, 223, 288, 224, 256) AND topic_type=1 and topic_sticky_flag > 0 GROUP BY t.forum_id HAVING count_sticky <5"; $result = mysqli_query($link, $query) ; echo "now ready to get row\n"; while($row2 = mysqli_fetch_assoc($result)); { echo "got row\n"; print($row2); echo gettype($row2); } output is: now ready to get row got row NULL So here I used only php with no 3rd party sofware or functions. And this IS a PHP bug. Hope this additional hode will make it clear. Thank you for your attention.