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 ?
0
give a positive ratinggive a negative rating
11 Aug 2021 at 08:30 AM
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;

Fetch_row returns an output:

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

Fetch_assoc returns an output:

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

Fetch_array returns an output:

[0] => 1,
[1] => "Brandon",
[2] => "Pro",
[user_id] => 1,
[user_name] => "Brandon",
[user_account] => "Pro"
0
give a positive ratinggive a negative rating
15 Aug 2021 at 11:43 AM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
2024 AnswerTabsTermsContact us