Book Image

Object-Oriented Programming with PHP5

By : Hasin Hayder
Book Image

Object-Oriented Programming with PHP5

By: Hasin Hayder

Overview of this book

<p>Some basic objected-oriented features were added to PHP3; with PHP5 full support for object-oriented programming was added to PHP. Object-oriented programming was basically introduced to ease the development process as well as reduce the time of development by reducing the amount of code needed. OOP can greatly improve the performance of a properly planned and designed program.</p> <p>This book covers all the general concepts of OOP then shows you how to make use of OOP in PHP5, with the aid of an ample number of examples.</p>
Table of Contents (15 chapters)
Object-Oriented Programming with PHP5
Credits
About the Author
About the Reviewers
Introduction
Index

Adding Database Support


Our framework must have a data abstraction layer to facilitate database operations painlessly. We are going to provide support to three popular databases: SQLite, PostgreSQL, and MySQL. Here is the code of our data abstraction layer in core/main/db.php:

<?
include_once("dbdrivers/abstract.dbdriver.php");
class db
{
  private $dbengine;
  private $state  = "development";

  public function __construct()
  {
    $config = loader::load("config");
    $dbengineinfo = $config->db;
    if (!$dbengineinfo['usedb']==false)
    {
      $driver = $dbengineinfo[$this->state]['dbtype'].'driver';
      include_once("dbdrivers/{$driver}.php");
      $dbengine = new $driver($dbengineinfo[$this->state]);
      $this->dbengine = $dbengine;
    }
  }

  public function setDbState($state)
  {
    //must be 'development'/'production'/'test' or whatever
    if (empty($this->dbengine)) return 0;
    $config = loader::load("config");
    $dbengineinfo = $config->db;...