Mysqli fetch_assoc vs fetch_array

前端 未结 4 1937
心在旅途
心在旅途 2020-12-03 05:33

When I\'m returning one row from a table, to gather the results I usually use e.g.:

$info = $result->fetch_assoc(); 

What is the differ

4条回答
  •  盖世英雄少女心
    2020-12-03 06:17

    It's all about performance

    fetch_array() returns one array with both numeric keys, and associative strings (column names), so here you can either use $row['column_name'] or $row[0]

    Where as fetch_assoc() will return string indexed key array and no numeric array so you won't have an option here of using numeric keys like $row[0].

    So the latter one is better in performance compared to fetch_array() and obviously using named indexes is far better compared to numeric indexes.

提交回复
热议问题