Zpixel wrote:does the query above load the whole result into memory?
Depends on whose memory you're talking about. It will load the results into memory as a sort of temporary table on the database server, yes. As far as the webserver and/or the PHP process, no, that statement only increases the memory usage slightly - just enough to add a reference to the new resource.
The data will be copied into PHP's memory as you use the fetch commands, so if you overwrite the same variable on each iteration of some sort of loop, then you should only be using enough memory to hold one row of data at any given time.