Easy Tutorial
❮ Func Xml Parser Free Func Math Is Nan ❯

PHP mysqli_fetch_array() Function

PHP MySQLi Reference Manual

Fetch a row as a numeric array or an associative array from the result set:

mysqli_fetch_array()

<?php 
// Assume database username: root, password: 123456, database: tutorialpro 
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

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

// Numeric array
$row = mysqli_fetch_array($result, MYSQLI_NUM);
printf("%s : %s", $row[0], $row[1]);

// Associative array
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
printf("%s : %s", $row["name"], $row["url"]);

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

mysqli_close($con);
?>

Definition and Usage

The mysqli_fetch_array() function fetches a row as an associative array, a numeric array, or both.

Note: The field names returned by this function are case-sensitive.


Syntax

Parameter Description
result Required. Specifies a result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result().
resulttype Optional. Specifies what type of array should be produced. Can be one of the following values: MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH

Technical Details

Return Value: Returns an array of strings that corresponds to the fetched row. Returns NULL if there are no more rows in the result set.
PHP Version: 5+
--- ---
❮ Func Xml Parser Free Func Math Is Nan ❯