A web site that exists for database access should be planned around the database. First, decide what sort of load the database will have to handle, and then choose web server software and hardware based on that load. The database will probably have to do much more work than the web server, so the database will be the bottleneck.
You can store a preparsed statement in the database with variables in specific positions. These variables are called “bind variables.” The performance of prepared statements is much greater than statements that must be parsed and optimized before execution, but there is overhead in setting up the statement to begin with.
Prepared statements are best used when you will be making many nearly identical queries, differing only in the value of specific query values rather than differing in structure or tables. Note that the storage of a prepared statement is rather expensive, so that is the part you want to do only once, not in a loop.
Some performance gains can be had simply by storing the most common data together in the same tables, avoiding expensive join operations. This also makes it easier to write queries, since a single table can then be used where otherwise you would have to do a join. On the other hand, denormalized tables increases the possibility of data inconsistencies, where data that is supposedly identical is different in different tables. Denormalized tables are also ...