HomeMySQL Abstracting Access to MySQL for an MVC-Based Framework in PHP 5
Abstracting Access to MySQL for an MVC-Based Framework in PHP 5
In this third part of the series, I further enhance the functionality of this sample MVC framework by adding a class to it that takes care of interacting with MySQL in a simple manner. You’ll see the importance of this abstraction class when I show you the definition of the corresponding model, which will aggregate an instance of “MySQL” to handle the data layer very easily.
Despite how intimidating this task may sound to you, building a framework in PHP 5 that follows the structure imposed by the Model-View-Controller design pattern is much easier than you may think.
So, if you’re interested in learning the key concepts that surround this process, either for building your own MVC-based framework or simply for understanding more clearly the underlying logic of existing ones, then start reading right now!
Welcome to the third episode of a series that shows you how to build a simple MVC-based framework in PHP 5. This series walks you through the progressive development of a basic framework with PHP 5 that uses the functionality provided by the MVC design pattern to separate business and application logic from visual presentation.
And now that you’re aware of the goal of this series, it’s time to review the topics that were treated in the last installment. In the last article I left off by adding to the framework a router/dispatcher class. This class was tasked first with parsing all of the users requests, then instantiating when possible the appropriate controller class, and finally calling a method that matches a specific portion of that request.
In many production frameworks, the routing and dispatching processes are performed by separate classes or modules, but for the sake of simplicity the framework that I’m building here will execute those tasks by using a single class.
Having outlined the basic functioning of the router/dispatcher class, it’s time to continue extending the framework’s existing functionality. In this third chapter of the series I’m going to build a basic MySQL abstraction class to interact with a specified database, which will be the default persistent storage mechanism used by the framework.
To learn the full details for how this new class will be developed, click on the link below and read the next few lines!