Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
model.php
Package: ext-3.1.0.zip [view]
Upload User: dawnssy
Upload Date: 2022-08-06
Package Size: 9345k
Code Size: 2k
Category:
JavaScript
Development Platform:
JavaScript
- <?php
- /**
- * @class Model
- * Baseclass for Models in this imaginary ORM
- */
- class Model {
- public $id, $attributes;
- static function create($params) {
- $obj = new self(get_object_vars($params));
- $obj->save();
- return $obj;
- }
- static function find($id) {
- global $dbh;
- $found = null;
- foreach ($dbh->rs() as $rec) {
- if ($rec['id'] == $id) {
- $found = new self($rec);
- break;
- }
- }
- return $found;
- }
- static function update($id, $params) {
- global $dbh;
- $rec = self::find($id);
- if ($rec == null) {
- return $rec;
- }
- $rs = $dbh->rs();
- foreach ($rs as $idx => $row) {
- if ($row['id'] == $id) {
- $rec->attributes = array_merge($rec->attributes, get_object_vars($params));
- $dbh->update($idx, $rec->attributes);
- break;
- }
- }
- return $rec;
- }
- static function destroy($id) {
- global $dbh;
- $rec = null;
- $rs = $dbh->rs();
- foreach ($rs as $idx => $row) {
- if ($row['id'] == $id) {
- $rec = new self($dbh->destroy($idx));
- break;
- }
- }
- return $rec;
- }
- static function all() {
- global $dbh;
- return $dbh->rs();
- }
- public function __construct($params) {
- $this->id = isset($params['id']) ? $params['id'] : null;
- $this->attributes = $params;
- }
- public function save() {
- global $dbh;
- $this->attributes['id'] = $dbh->pk();
- $dbh->insert($this->attributes);
- }
- public function to_hash() {
- return $this->attributes;
- }
- }