mysqli_result::fetch_assoc
(mysqli_fetch_assoc) Get the result row as an associative array
fetch_assoc()
/ mysqli_fetch_assoc()
function gets the result row in the form of an associative array.
Note: The field names returned from this function are case sensitive.
Get the result row in the form of an associative array:
<?php $mysqli = new mysqli ( "localhost" , "my_user" , "my_password" , "my_db" ) ; if ( $mysqli -> connect_errno ) { echo "Failed to connect to MySQL: " . $mysqli -> connect_error ; exit ( ) ; } $sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname" ; $result = $mysqli -> query ( $sql ) ; // Associate array $row = $result -> fetch_assoc ( ) ; printf ( "%s (%s)\n" , $row [ "Lastname" ] , $row [ "Age" ] ) ; // Release the result set $result -> free_result ( ) ; $mysqli -> close ( ) ; ?>
Get the result row in the form of an associative array:
<?php $con = mysqli_connect ( "localhost" , "my_user" , "my_password" , "my_db" ) ; if ( mysqli_connect_errno ( ) ) { echo "Failed to connect to MySQL: " . mysqli_connect_error ( ) ; exit ( ) ; } $sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname" ; $result = mysqli_query ( $con , $sql ) ; // Associate array $row = mysqli_fetch_assoc ( $result ) ; printf ( "%s (%s)\n" , $row [ "Lastname" ] , $row [ "Age" ] ) ; // Release the result set mysqli_free_result ( $result ) ; mysqli_close ( $con ) ; ?>
$mysqli_result -> fetch_assoc ( )
mysqli_fetch_assoc ( result )
parameter | describe |
---|---|
result | Required. Specifies the result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result(). |