When retrieving data from a database is it more efficient on server resources to always load the data from the database or write the data to a file and use a php include statement to load it? Or is there a better alternative than either of these?
Also, when querying a MySQL database for multiple specific records (ie ids: 1, 5, 27, 24) from a single table is it more efficient to combine the queries into one query or separate them into one query per record?
Well, that depends on a lot of things. The common approach is to first just do it with the database, if the site is getting slow, start with caching (that is actually writing the data somewhere else and retrieve it from there instead, but it’s originally still managed inside the database). The same works for the HTML that your site outputs, you can cache this server-side as well.
All sites with high-traffic use some kind of database and HTML caching.
Normally you use one query and the
IN()function to do that, e.g.... WHERE id IN(1, 5, 27, 24), because it’s easier for the database server to do this in one query instead of multiple ones.