International Developer Logo Last Updated 25.07.08 at 11.48
On Sale
This months front cover, click to see the table of contents.
Subscribe
 
TUTORIALS

Developing Three-Tier Web Applications with PHP


Daniel Winter   01.10.05


Step 2 - The Physical Database Model
The physical model of our database does not exactly correspond to the logical model used by the application. Although each student and teacher object will have an address, for instance, these details will be stored in a separate table. This is done so that the less-used columns are kept separate to the commonly used fields, thereby maximising the throughput for queries that don't need any address details. The actual database layout consists of the five tables shown here:

CREATE TABLE `students` (
  `id` int(11) NOT NULL auto_increment,
  `firstname` varchar(255) NOT NULL,
  `surname` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE `teachers` (
  `id` int(11) NOT NULL auto_increment,
  `firstname` varchar(255) NOT NULL,
  `surname` varchar(255) NOT NULL,
  `email` varchar(255) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

CREATE TABLE `subjects` (
  `id` int(11) NOT NULL auto_increment,
  `Subject` varchar(255) NOT NULL,
  `teacherId` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

CREATE TABLE `enrolments` (
  `id` int(11) NOT NULL auto_increment,
  `studentId` int(11) NOT NULL,
  `subjectId` int(11) NOT NULL,
  `examResult` tinyint(4) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE `address` (
  `id` int(11) default NULL,
  `line1` varchar(255) NOT NULL,
  `line2` varchar(255) default NULL,
  `suburb` varchar(255) NOT NULL,
  `state` varchar(50) NOT NULL,
  `postcode` varchar(50) NOT NULL,
  `email2` varchar(255) default NULL,
  `phone` varchar(255) default NULL,
  `mobile` varchar(255) default NULL,
  `studentId` int(11) default NULL,
  `teacherId` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1




   Previous Page  1 2 3 4 5 6 7 8 9 10 ... Next Page   

HAVE YOUR SAY
This article is rated  Rate this article