PHPOF v1 Tutorial: Introduction

This page is about the original version of PHPOF (version 1). This has been superceded by the completely-rewritten PHPOF version 2.

Welcome to this PHPOF tutorial. The aim of this is to give you a crash course in using PHPOF which will hopefully demonstrate it's capabilities if you're a doubter, and get you off to a flying start if you're a new user. We're going to build a simple example Web application from scratch.

Please bear in mind that this tutorial aims to introduce the specifics of using PHPOF and is not a general tutorial on web programming. It assumes you are reasonably familiar with PHP, databases and object orientation. If not, this probably isn't the best place to start.

What you'll need

This tutorial uses the following files. Whilst key snippets from them will be included in this document, you might find it helpful to keep them open in a separate window for reference whilst reading this.

You're going to need a simple database and database table set up. Here's the appropriate CREATE TABLE statement for MySQL:

CREATE TABLE products (
  id int NOT NULL auto_increment,
  category varchar(2) NOT NULL default 'misc'
  name varchar(127) NOT NULL default '',
  descr text,
  image blob,
  price int(11) NOT NULL default '0',
  PRIMARY KEY (id)
);

and here's one for PostgreSQL:

CREATE TABLE products (
  id SERIAL,
  category varchar(2) NOT NULL default 'misc'
  name varchar(127) NOT NULL default '',
  descr FIXMEtext,
  image oid,
  price int(11) NOT NULL default '0',
  PRIMARY KEY (id)
);

I'm also going to assume that you've got the PHPOF modules somewhere in your include path. You could either do this by adding the path where they are stored to your php.ini file (which would make it global, across all sites on your server), or you could do it on a per-virtual-host basis with a line something like the following in your virtual server config within httpd.conf (assuming you're using Apache with mod_php):

php_value include_path .:/path/to/phpof

Next: Creating the derived classes >