Latest web development tutorials

PHP mysqli_fetch_all () function

PHP MySQLi Reference Manual PHP MySQLi Reference Manual

Examples

Fetch a result row as an associative array of all:

<? php
// Assumes that the database username: root, password: 123456, database: w3big
$ con = mysqli_connect ( "localhost" , "root", "123456", "w3big");
if (mysqli_connect_errno ($ con))
{
echo "MySQL connection failed:" mysqli_connect_error ();.
}

$ sql = "SELECT name, url FROM websites ORDER BY alexa";
$ result = mysqli_query ($ con, $ sql);

// retrieve data
mysqli_fetch_all ($ result, MYSQLI_ASSOC);

// Release the result set
mysqli_free_result ($ result);

mysqli_close ($ con);
?>

Definition and Usage

mysqli_fetch_all () function Fetch all rows as an associative array, a numeric array, or both from the results.

Note: This function is available only when with MySQL Native Driver.


grammar

mysqli_fetch_all( result,resulttype ) ;

参数 描述
result 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。
resulttype 可选。规定应该产生哪种类型的数组。可以是以下值中的一个:
  • MYSQLI_ASSOC
  • MYSQLI_NUM
  • MYSQLI_BOTH

technical details

return value: Returns an array or associative array containing the result of the digital line.
PHP version: 5.3+


PHP MySQLi Reference Manual PHP MySQLi Reference Manual