| 
<?php
 ini_set("max_execution_time",3);
 $start = microtime(true);
 
 include_once("TBit.class.php");
 include_once("TEnum.class.php");
 include_once("TLob.class.php");
 include_once("TNumber.class.php");
 include_once("TString.class.php");
 include_once("TTimestamp.class.php");
 include_once("TypedStruct.class.php");
 include_once("TypeSafeStruct.class.php");
 
 /**
 * CREATE TABLE `orders` (
 `orderNumber` int(11) NOT NULL,
 `orderDate` datetime NOT NULL,
 `requiredDate` datetime NOT NULL,
 `shippedDate` datetime DEFAULT NULL,
 `status` varchar(15) NOT NULL,
 `comments` text,
 `customerNumber` int(11) NOT NULL,
 PRIMARY KEY (`orderNumber`)
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 INSERT INTO `orders` VALUES ('10100', '2003-01-06 00:00:00', '2003-01-13 00:00:00', '2003-01-10 00:00:00', 'Shipped', null, '363');
 INSERT INTO `orders` VALUES ('10101', '2003-01-09 00:00:00', '2003-01-18 00:00:00', '2003-01-11 00:00:00', 'Shipped', 'Check on availability.', '128');
 INSERT INTO `orders` VALUES ('10102', '2003-01-10 00:00:00', '2003-01-18 00:00:00', '2003-01-14 00:00:00', 'Shipped', null, '181');
 INSERT INTO `orders` VALUES ('10103', '2003-01-29 00:00:00', '2003-02-07 00:00:00', '2003-02-02 00:00:00', 'Shipped', null, '121');
 INSERT INTO `orders` VALUES ('10104', '2003-01-31 00:00:00', '2003-02-09 00:00:00', '2003-02-01 00:00:00', 'Shipped', null, '141');
 INSERT INTO `orders` VALUES ('10105', '2003-02-11 00:00:00', '2003-02-21 00:00:00', '2003-02-12 00:00:00', 'Shipped', null, '145');
 INSERT INTO `orders` VALUES ('10106', '2003-02-17 00:00:00', '2003-02-24 00:00:00', '2003-02-21 00:00:00', 'Shipped', null, '278');
 INSERT INTO `orders` VALUES ('10107', '2003-02-24 00:00:00', '2003-03-03 00:00:00', '2003-02-26 00:00:00', 'Shipped', 'Difficult to negotiate with customer. We need more marketing materials', '131');
 INSERT INTO `orders` VALUES ('10108', '2003-03-03 00:00:00', '2003-03-12 00:00:00', '2003-03-08 00:00:00', 'Shipped', null, '385');
 
 */
 class Model_Orders extends TypeSafeStruct {
 
 private $int_OrderNumber;
 private $datetime_OrderDate;
 private $datetime_RequiredDate;
 private $datetime_ShippedDate;
 private $varchar_Status;
 private $text_Comments;
 private $int_CustomerNumber;
 
 public function __set($key,$value) {
 $this->hasProperty($key);
 $type = $this->getPropertyType($key);
 if($type) {
 $this->{$type."_".self::ucfirstAndCamelcased($key)} = $value;
 } else {
 $this->{"set".$key}($value);
 }
 }
 
 public function __get($key) {
 return $this->{$key};
 }
 
 }
 
 // begin data operations
 $link = mysql_connect('localhost', 'root', 'pwd');
 if (!$link) die('no connection established: ' . mysql_error());
 
 $db = mysql_select_db('dbase', $link);
 if (!$db)die ('no able to use db: ' . mysql_error());
 
 $result = mysql_query("SELECT * FROM orders LIMIT 4;");
 if(!$result) die("no result set: ". mysql_error());
 
 // begin view operations
 while($row=mysql_fetch_object($result, "Model_Orders")){
 echo $row->getOrderNumber() . "|" . $row->getOrderDate()->daysInMonth().", ". $row->getOrderDate()->weekNumber().", ". $row->getOrderDate()->get()->format("d.m.Y") . "\n";
 }
 
 mysql_close($link);
 
 $end = microtime(true);
 echo "\n".number_format($end - $start, 5);
 
 
 |