Difference between Fetch_assoc, Fetch_array, Fetch_row - MySQL

What is the difference between Fetch_assoc, Fetch_array and Fetch_row in MySQL. When is it effective to use each of them ?
11 Aug 2021 at 08:30 AM
0pnshow more
StorStor
Hi,

There are differences between using Fetch_assoc, Fetch_array and Fetch_row. Each of them is effective in different situations, so it depends on your needs. In specific solutions, some of them may be faster or slower.

  • Fetch_row - returns a numeric array of strings that corresponds to the fetched row, or false if there are no rows.
  • Fetch_assoc - returns an associative array of strings that corresponds to the fetched row, or false if there are no rows.
  • Fetch_array - is a combination of Fetch_row and Fetch_assoc. It returns both numeric array and associative array of strings that corresponds to the fetched row.







For example can be used SQL query SELECT user_id, user_name, user_account FROM users;

Mysqli_fetch_row returns an output:

[0] => 1,
[1] => "Brandon",
[2] => "Pro"

Mysqli_fetch_assoc returns an output:

[user_id] => 1,
[user_name] => "Brandon",
[user_account] => "Pro"

Mysqli_fetch_array returns an output:

[0] => 1,
[1] => "Brandon",
[2] => "Pro",
[user_id] => 1,
[user_name] => "Brandon",
[user_account] => "Pro"
15 Aug 2021 at 11:43 AM
0pnshow more
TimTim
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook & Twitter
2021 AnswerTabsTermsContact us