I have a request:

$selpublist = $mysqli->query("SELECT `vk_id` FROM `groups`", MYSQLI_STORE_RESULT); 

On the local server, it worked, and after moving to hosting it refuses to work. var_dump($selpublist) :

 object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> NULL ["num_rows"]=> int(17) ["type"]=> int(0) } 

With the database, everything is fine, phpmyadmin selects everything, too, is normal. Hoster says that this is not their problem. Php version 5.3.

After executing the query, I output the data through a cycle:

 foreach ( $selpublist as $group ) { } 

What to do?

  • So, examples should be looked at how to do it correctly - BOPOH
  • @BOPOH I output the result using a loop, and the loop does not output anything. - devtwo
  • and even watched examples? there the cycle is done differently: while ($row = $result->fetch_assoc()) {...} , this is not the same thing as yours - BOPOH
  • But for some reason, this cycle worked before. - devtwo
  • @BOPOH earned that. If you want, write the answer so that I can mark it. - devtwo

1 answer 1

Read the documentation http://php.net/manual/ru/mysqli.query.php

Returns FALSE on failure. If the SELECT, SHOW, DESCRIBE, or EXPLAIN queries succeed, mysqli_query () will return a mysqli_result object. For other successful queries, mysqli_query () returns TRUE.

And further about mysqli_result

 mysqli_result::$current_field — Получает смещение указателя по отношению к текущему полю mysqli_result::data_seek — Перемещает указатель результата на выбранную строку mysqli_result::fetch_all — Выбирает все строки из результирующего набора и помещает их в ассоциативный массив, обычный массив или в оба mysqli_result::fetch_array — Выбирает одну строку из результирующего набора и помещает ее в ассоциативный массив, обычный массив или в оба mysqli_result::fetch_assoc — Извлекает результирующий ряд в виде ассоциативного массива mysqli_result::fetch_field_direct — Получение метаданных конкретного поля mysqli_result::fetch_field — Возвращает следующее поле результирующего набора mysqli_result::fetch_fields — Возвращает массив объектов, представляющих поля результирующего набора mysqli_result::fetch_object — Возвращает текущую строку результирующего набора в виде объекта mysqli_result::fetch_row — Получение строки результирующей таблицы в виде массива mysqli_result::$field_count — Получение количества полей в результирующем наборе mysqli_result::field_seek — Установить указатель поля на определенное смещение mysqli_result::free — Освобождает память занятую результатами запроса mysqli_result::$lengths — Возвращает длины полей текущей строки результирующего набора mysqli_result::$num_rows — Получает число рядов в результирующей выборке 
  • After getting the data, I output it using a loop, but nothing is output. I updated the question. - devtwo