Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://php.net/mysql_fetch_array" rel="noreferrer"><code>mysql_fetch_array</code></a> will get you an array that can have as keys :</p> <ul> <li>both numbers and names of columns, if using <code>MYSQL_BOTH</code> </li> <li>columns names, using <code>MYSQL_ASSOC</code> -- in this case, you'll get the same thing you get when using <code>mysql_fetch_assoc</code></li> <li>only numbers (depending on the order of columns in the query), if using <code>MYSQL_NUM</code></li> </ul> <p>Getting results indexed by columns names is probably the most useful solution -- easier to use, at least.</p> <p>But getting results indexed by the positions of the fields in the select clause is interesting in one situtation : when you have several columns that have the same name or alias. <br>In this case, as you cannot have two entries with the same index in an array, you will be able to access only one of those columns using the column name as index. <br>For the other columns that have the same name, you'll have to use numeric indexes.</p> <p>That situation is probably the only case for which I would use <code>mysql_fetch_array</code> -- and I rather prefer using aliases in my query, to avoid that situation -- it's more clear, in my opinion.</p> <p><br> <a href="http://php.net/mysql_fetch_assoc" rel="noreferrer"><code>mysql_fetch_assoc</code></a> will get you an array, with columns names as keys, and data as values.</p> <p>Not much to say, actually.</p> <p><br> And <a href="http://php.net/mysql_fetch_object" rel="noreferrer"><code>mysql_fetch_object</code></a> will get you objetcs in return.</p> <p><br> Choosing between <code>mysql_fetch_assoc</code> and <code>mysql_fetch_object</code> most probably depend on how you develop your application : if using objects everywhere, the second one is probably the most suited.</p> <p>If using arrays as data-containers, you can just go with the first one.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload