Edit report at https://bugs.php.net/bug.php?id=65827&edit=1
ID: 65827 Updated by: m...@php.net Reported by: ilantipov at gmail dot com Summary: error passing mysqli_fetch_assoc results back Status: Not a bug Type: Bug Package: MySQLi related Operating System: Ubuntu 12.04.1 LTS PHP Version: 5.4.20 Block user comment: N Private report: N New Comment: You've a dangling semi-colon in your while statement. Previous Comments: ------------------------------------------------------------------------ [2013-10-03 16:41:18] 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 16:01:20] m...@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 15:43:58] 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 15:10:02] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65827&edit=1