Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does MYSQLI_NUM mean and do?

Tags:

php

mysql

I just wanted a little bit of information on MYSQLI_NUM. And is it part of PHP or MySQL.

like image 439
aBc Avatar asked Nov 06 '09 02:11

aBc


People also ask

What is the use of Mysqli_fetch_array?

The fetch_array() / mysqli_fetch_array() function fetches a result row as an associative array, a numeric array, or both. Note: Fieldnames returned from this function are case-sensitive.

What is the difference between Fetch_assoc and Fetch_array?

fetch_array returns value with indexing. But Fetch_assoc just returns the the value. here array location 0 contains 11 also this location name is 'id'. means just returns the value.

What is Mysqli_both?

MYSQLI_BOTH will create a single array with the attributes of MYSQLI_NUM and MYSQLI_ASSOC. From the documentation: By using the MYSQLI_ASSOC constant this function will behave identically to the mysqli_fetch_assoc(), while MYSQLI_NUM will behave identically to the mysqli_fetch_row() function.

What is mysqli_result?

The mysqli_result class ¶Represents the result set obtained from a query against the database.


2 Answers

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.

like image 110
Travis Avatar answered Oct 13 '22 20:10

Travis


It is a PHP constant used in mysqli_fetch_array()

This tells the function that you want it to return a record from your results as a numerically indexed array instead of an associative one (MYSQLI_ASSOC) or both (MYSQLI_BOTH).

Alternatively, you can just use mysqli_fetch_row() to do the same thing.

like image 22
HorusKol Avatar answered Oct 13 '22 20:10

HorusKol