<?php
 
// sample model console script
 
 
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");
 
 
# sample sql
 
/**
 
 *SET FOREIGN_KEY_CHECKS=0;
 
-- ----------------------------
 
-- Table structure for city
 
-- ----------------------------
 
DROP TABLE IF EXISTS `city`;
 
CREATE TABLE `city` (
 
  `ID` int(11) NOT NULL AUTO_INCREMENT,
 
  `Name` char(35) NOT NULL DEFAULT '',
 
  `CountryCode` char(3) NOT NULL DEFAULT '',
 
  `District` char(20) NOT NULL DEFAULT '',
 
  `Population` int(11) NOT NULL DEFAULT '0',
 
  PRIMARY KEY (`ID`)
 
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=latin1;
 
INSERT INTO `city` VALUES ('1', 'Kabul', 'AFG', 'Kabol', '1780000');
 
INSERT INTO `city` VALUES ('2', 'Qandahar', 'AFG', 'Qandahar', '237500');
 
INSERT INTO `city` VALUES ('3', 'Herat', 'AFG', 'Herat', '186800');
 
INSERT INTO `city` VALUES ('4', 'Mazar-e-Sharif', 'AFG', 'Balkh', '127800');
 
INSERT INTO `city` VALUES ('5', 'Amsterdam', 'NLD', 'Noord-Holland', '731200');
 
INSERT INTO `city` VALUES ('6', 'Rotterdam', 'NLD', 'Zuid-Holland', '593321');
 
INSERT INTO `city` VALUES ('7', 'Haag', 'NLD', 'Zuid-Holland', '440900');
 
INSERT INTO `city` VALUES ('8', 'Utrecht', 'NLD', 'Utrecht', '234323');
 
INSERT INTO `city` VALUES ('9', 'Eindhoven', 'NLD', 'Noord-Brabant', '201843');
 
INSERT INTO `city` VALUES ('10', 'Tilburg', 'NLD', 'Noord-Brabant', '193238');
 
 
 */
 
 
# sample model
 
class Model_City extends TypeSafeStruct {
 
 
    private $int_ID;
 
    private $char_Name;
 
    private $char_CountryCode;
 
    private $char_District;
 
    private $int_Population;
 
 
    public function __set($key,$value) {
 
        $type = $this->getPropertyType($key);
 
        if($type and $this->hasProperty($key)) {
 
            $this->{$type."_".$key} = $value;
 
        } else {
 
            $this->{"set".$key}($value);
 
        }
 
    }
 
 
    public function __get($key) {
 
        return $this->{$key};
 
    }
 
 
}
 
 
// begin data operations
 
$link = mysql_connect('localhost', 'root', 'pssword');
 
if (!$link) die('no connection established: ' . mysql_error());
 
 
$db = mysql_select_db('tete', $link);
 
if (!$db)die ('no able to use db: ' . mysql_error());
 
 
$result = mysql_query("SELECT * FROM City LIMIT 4;");
 
if(!$result) die("no result set: ". mysql_error());
 
 
// begin view operations
 
while($row=mysql_fetch_object($result, "Model_City")){
 
    echo $row->getName()->toUpper()->padRight(15);
 
    echo $row->getCountryCode()->toUpper()->padRight(5);
 
    echo $row->getDistrict()->toUpper()->padRight(15);
 
    echo $row->getPopulation()->format(0,",",".");
 
    echo "\n";
 
}
 
 
mysql_close($link);
 
 
 
 
 
 
$end = microtime(true);
 
echo "\n".number_format($end - $start, 5);
 
 
 
 |