Your Tables as PHP Objects

The Code Generator will usually create a PHP object for each table in your database. The exception is a special kind of table used to define many-to-many relationships, and that is discussed later in the tutorial. For our three main tables (login, person and project), the Code Generator created the following PHP classes:

LoginGen, PersonGen and ProjectGen are the generated classes which contain all the code to handle basic database CRUD (create, restore, update and delete) functionality. These files are recreated every time you generate code.

The Login, Person and Project classes inherit from the generated classes, and they are known as custom subclasses. They get generated only if they do not exist, and then are not changed by the code generator. So you should feel free to make changes to these custom subclasses, override methods, introduce additional functionality, etc. as well as re-execute the code generator at any time. Your changes and class customizations will remain intact.

For every object, the Code Generator will generate the getter and setter methods for each of the attributes in the table. It will also generate the following basic CRUD methods:

The example below shows how we can use the load() and loadAll() methods and the properties to view some of the data. Feel free to click on View Source button to view the PHP code for objects.php which makes these calls.

Displaying the Properties of a Project

Using LoadAll to get an Array of Person Objects

Using countAll() to get a Count of All Persons in the Database

There are 16 person(s) in the system.