There can be no performance critical looping without a couple of core points like a separate prepare/execute set of statements.
And the concept of DBI:DBD is greeat for moving between databases unless you tie yourself down on purpose.