Just some of the things that came up: make sure you don't create prepared statements in your loops. There is some overhead, but it pays for itself after the third request or so. In fact, with a large list of parameters, it can be even faster for a single request.
Something that significantly speeds up the work, fulfills all your requests in one (or several large) transactions. If these are large data sets, you can get 1000 transaction requests or something like that. (Of course, the semantics of your domain model should take this into account, but in my experience this is almost always the case).
The number of queries that you can bind in a single transaction depends on the database, so some experimentation and reading may be required.
Peter Tillemans
source share