Simple question I can’t seem to find the answer to.
I’m trying to squeeze some more performance out of this large app and I’m wondering if switching all of the mysql_fetch_array() function calls to only use MYSQL_ASSOC will make any difference.
It seems like it would since it’s creating an array with just:
$row['field1'] = 'field1-value';
instead of both numeric and associative keys for the same field:
$row[0] = 'field1-value';
$row['field1'] = 'field1-value';
There are two concepts prevalent in this scenario, which you must consider:-
It is always helpful to use the associative indices of “
MYSQL_ASSOC” / “MYSQL_BOTH“, instead of just using the numerical indices, because the order of the fields may change in the lifetime of the website. If you understand & agree with this point, then you can use the “MYSQL_ASSOC” result type, instead of the “MYSQL_BOTH” result type.If you are concerned about how much memory is being used for queries that return large result sets, then you can use “
mysql_free_result()” function. More details of this function can be found here. However, all the associated result memory is automatically freed at the end of the script’s execution.Now, coming back to your question, I think that from a performance point of view, using “
MYSQL_ASSOC” result type may result in saving a little bit of memory of the server (where the website has been hosted, when the relevant web page is being executed by the PHP Parser), but you must also ensure & understand the above points as well.Hope it helps.