What is the best use (to save machine resources) for mysql_fetch_array:
$listidsquery = mysql_query("SELECT * FROM database") or die(mysql_error());
while($listidsres=mysql_fetch_array($listidsquery)){
results;
}
or
while($listidsres=mysql_fetch_array(mysql_query("SELECT * FROM database"))){
results;
}
Thanks.
The first snippet is the correct one, and will yield superior performance. The first one sets a mysql resultset resource to
$listidres– a resource is a simple integer value. It will therefore not consume any significant additional resources.The second snippet is not correct at all. It will re-execute the query for each iteration of the loop (and will therefore likely result in an infinite loop).
As was stated in the comments above, both snippets are using the
mysqllibrary, which is EOL. You should move tomysqliinstead.