If you get an empty set after calling fetch_all(), make sure the result set cursor is reset to the beginning
mysqli_result::fetch_all
mysqli_fetch_all
(PHP 5 >= 5.3.0)
mysqli_result::fetch_all -- mysqli_fetch_all — Obtener todas las filas en un array asociativo, numérico, o en ambos
Descripción
Estilo orientado a objetos
Estilo por procesos
mysqli_fetch_all() consulta todas las filas y devuelve el resultado en un array asociativo, numérico, o ambos.
Parámetros
- result
-
Sólo estilo procedimental: Un conjunto de identificadores de resultados devuelto por mysqli_query(), mysqli_store_result() o mysqli_use_result().
- resulttype
-
Este parámetro opcional define mediante una constante qué tipo de array debe producirse a partir de los datos actuales. Los valores posibles para este parámetro son las constantes MYSQLI_ASSOC, MYSQLI_NUM, o MYSQLI_BOTH.
Valores devueltos
Devuelve un array asociativo o numérico que almacena el resultado.
MySQL Native Driver Only
Disponible sólo con mysqlnd.
Dado que mysqli_fetch_all() devuelve todas las filas en un array en un solo paso, puede consumir más memoria que otras funciones similares tales como mysqli_fetch_array(), que sólo devuelve una fila cada vez a partir del resultado. Por tanto, si se necesita recorrer un resultado, será necesario un bucle que minimice el impacto en rendimiento. Por esta razón, se aconseja que sólo se use mysqli_fetch_all() en aquellas situaciones en que el resultado se tenga que enviar a otra capa o nivel para que lo procese.
Ver también
- mysqli_fetch_array() - Fetch a result row as an associative, a numeric array, or both
- mysqli_query() - Performs a query on the database
Return value changed in 5.3.3 - between 5.3.0 and 5.3.2 (incl.) when the result set was empty NULL was returned. 5.3.3+ returns an empty array.
Also, mysqli_fetch_all works only for buffered result sets, which are the default for mysqli_query. MYSQLI_USE_RESULT will be supported in 5.3.4+
However, it makes little sense to use it this way, materialising unbuffered sets. In this case choose STORE_RESULT, and fetch_all won't copy the data, but reference it, as it is stored already in mysqlnd.
If you are getting the following error:
Fatal error: Call to undefined method mysqli_result::fetch_all()
Be sure you didn't miss this line after the procedural call about it requiring mysqlnd
