Can someone tell me just what is going on in the background of a database when a query is executed? Obviously the database collects and weeds out records as per the query instructions, and then PHP is able to further "work" with the selected records. This seems to suggest that the database is storing the results in a specific spot that can be accessed by the user running the query. If that is true, I would like to learn all I can about the specifics of that process. How and where are the query results stored for use by PHP? When is that info cleared out? Any info along these lines would be a great help.
It helps to state which database you are using. If you are using MySQL, you can try using the EXPLAIN feature. It may not tell you everything that you are asking in your post, but it's a start.
Do a search at the MySQL manual for syntax.
better yet ir you're using any open source dbms just read the source code.