php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65827 error passing mysqli_fetch_assoc results back
Submitted: 2013-10-03 15:10 UTC Modified: 2013-10-03 17:38 UTC
From: ilantipov at gmail dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.4.20 OS: Ubuntu 12.04.1 LTS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ilantipov at gmail dot com
New email:
PHP Version: OS:

 

 [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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-03 15:43 UTC] ilantipov at gmail dot com
php configure options  ./configure   --enable-fpm   --enable-libxml   --with-mcrypt   --enable-mbstring   --with-gd   --with-mysql-sock   --with-mysqli=mysqlnd   --with-pdo-mysql=mysqlnd   --with-mysql=mysqlnd   --enable-sockets   --with-iconv   --with-gettext   --with-zlib   --with-freetype-dir=/usr   --with-jpeg-dir=/usr   --prefix=/usr/local/php-fpm   --with-config-file-path=/usr/local/php-fpm/etc   --with-config-file-scan-dir=/usr/local/php-fpm/etc/conf.d   --with-fpm-user=www-data   --with-fpm-group=www-data   --disable-simplexml   --disable-xmlreader   --disable-xmlwriter   --disable-tokenizer   --without-sqlite3   --without-pdo-sqlite   --with-curl
 [2013-10-03 16:01 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2013-10-03 16:01 UTC] mike@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 [2013-10-03 16:41 UTC] ilantipov at gmail dot com
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.
 [2013-10-03 17:19 UTC] mike@php.net
You've a dangling semi-colon in your while statement.
 [2013-10-03 17:38 UTC] ilantipov at gmail dot com
Thank you so much for your patience. That's really a silly mistake, that none of 3 programmers noticed and didn't change in their own tests. Thanks a lot.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 04:01:29 2024 UTC