Easy Tutorial
❮ Func String Stripslashes Func Math Cosh ❯

PHP mysqli_fetch_assoc() Function

PHP MySQLi Reference Manual

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

mysqli_fetch_assoc()

<?php 
// Assuming 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);

// Associative array
$row = mysqli_fetch_assoc($result);
printf("%s (%s)\n", $row["name"], $row["url"]);

// Free result set
mysqli_free_result($result);

mysqli_close($con);
?>

Definition and Usage

The mysqli_fetch_assoc() function fetches a row as an associative array from the result set.

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().

Technical Details

Return Value: Returns an associative array representing the fetched row. Returns NULL if there are no more rows in the result set.
PHP Version: 5+
--- ---
❮ Func String Stripslashes Func Math Cosh ❯