Once the PHP page is done displaying the first HTML page, it stops running and the object is gone. You can use Ajax to prevent another page reload but you'll still need to start a new PHP page that performs the query again.
The query you described is usually lightweight enough that it can be executed a dozen times a second with no serious impact on server performance. If your query was taking more than 2 seconds to perform, that could be a serious problem if you had a hundred visitors in a 20 second window and you might want to consider caching the result of the query in a text file or something.
You should benchmark your web site to see what it can actually handle. You can run a program called "ab" (apache benchmark) that will hit your site as fast as it can and tell you how many times your web page can be viewed in a certain amount of time.
If it turns out that your site can handle 1000 times the traffic you expect to get, then sure, optimization is still important, but maybe it's not the biggest concern on your plate.
I suspect that in a C/C++ environment, you are used to scripts running for as long as the user keeps them open? In web development, 98% of my scripts are designed to run for 1/10th of a second and then disappear with no expectation that the object will persist.
Disclaimer: That's just been my experience. Programmers for Amazon, Ebay, Yahoo and Google probably have clever ways to optimize a site that I don't know about.