Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences in mysqli_fetch functions

Tags:

php

mysql

mysqli

This post gives four ways of retrieving the result of a MySQL query:

  • mysqli_fetch_array — Fetch a result row as an associative, a numeric array, or both

    $row = mysqli_fetch_array($result);
    echo $row[0]; // or
    echo $row['online'];
    
  • mysqli_fetch_assoc — Fetch a result row as an associative array

    $row = mysqli_fetch_assoc($result);
    echo $row['online'];
    
  • mysqli_fetch_object — Returns the current row of a result set as an object

    $row = mysqli_fetch_object($result);
    echo $row->online;
    
  • mysqli_fetch_row — Get a result row as an enumerated array

    $row = mysqli_fetch_row($result);
    echo $row[0];
    

Is there any significant difference between these four functions, in terms of either performance or functionality, or can they be used interchangeably?

like image 908
1'' Avatar asked Sep 02 '13 16:09

1''


1 Answers

Is there any significant difference between these four functions

No.

can they be used interchangeably?

Yes.

like image 70
Your Common Sense Avatar answered Oct 07 '22 18:10

Your Common Sense