php db middleware