Mysqli_fetch_assoc () retrieves one row from code reading.
While mysqli_fetch_all () calls mysqlnd_fetch_all (), which uses a loop to retrieve one row at a time until all rows are retrieved, then it will exit the loop.
Here is the corresponding function in mysqlnd edited for length:
MYSQLND_METHOD(mysqlnd_res, fetch_all)(MYSQLND_RES * result, unsigned int flags, zval *return_value TSRMLS_DC ZEND_FILE_LINE_DC) { ... do { MAKE_STD_ZVAL(row); mysqlnd_fetch_into(result, flags, row, MYSQLND_MYSQLI); if (Z_TYPE_P(row) != IS_ARRAY) { zval_ptr_dtor(&row); break; } add_index_zval(return_value, i++, row); } while (1); ... }
So, the answer is: from the point of view of the MySQL server, there is no such thing as a βfetchβ. PHP extensions either retrieve a single row or retrieve one row at a time until all rows in the result set are retrieved.
source share