Below are two methods commonly used in most php codes for fetch mysql data .
mysql_fetch_array()
mysql_fetch_assoc()
The "size" of the query results don't matter in this case.
mysql_fetch_array()
generally produces overhead by returning an associative array plus indexed results.
One should decide on the type of query and the desired results on whether to use mysql_fetch_array()
or mysql_fetch_assoc()
.
If the overhead is "neglectable" and I'm sure the query succeeds and I know there's only a single result, I occasionally do:
$q = mysql_query('SELECT `column1`,`column2` FROM `table` WHERE `id` = 123');
list($column1,$column2) = mysql_fetch_array($q);
mysql_free_result($q);
For iterative proceedings (like a while
loop), this just doesn't cut it. When there's no need for "quick-extracting" results (via a list
operator) and the result has to be further processed in code, I always use mysql_fetch_assoc()
*.
* When forced to actually use the quite out-dated procedural data retrieval functions of PHP. There are alternatives.