What does MYSQLI_NUM mean and do?

MYSQLI_NUM is a constant in PHP associated with a mysqli_result. If you’re using mysqli to retrieve information from the database, MYSQLI_NUM can be used to specify the return format of the data. Specifically, when using the fetch_array function, MYSQLI_NUM specifies that the return array should use numeric keys for the array, instead of creating an associative array. Assuming you have two fields in your database table, “first_field_name” and “second_field_name”, with the content “first_field_content” and “second_field_content”…

$result->fetch_array(MYSQLI_NUM);

fetches each row of the result like this:

array(
    0 => "first_field_content",
    1 => "second_field_content"
);

Alternatively…

$result->fetch_array(MYSQLI_ASSOC);

fetches an array like this:

array(
    "first_field_name" => "first_field_content",
    "second_field_name" => "second_field_content"
);

Using the constant MYSQLI_BOTH will fetch both.

Leave a Comment