5
Interacting with a Database
In this chapter, we explore practical techniques for integrating PHP applications with relational databases using classic design patterns. The first recipe shows you how to build a PDO-based database connection factory leveraging a central services container. Next, we demonstrate how AI agents can accelerate development by generating database entity classes from SQL definitions. We then walk through how you might build a flexible SQL query builder using the Builder design pattern. Finally, we address performance and cost efficiency by providing a recipe that defines a PSR-16 compliant caching class that stores and retrieves GenAI API responses directly from a database.
In this chapter we cover the following main ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access