Created
August 12, 2011 05:27
-
-
Save showsky/1141518 to your computer and use it in GitHub Desktop.
classGenericObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DB | |
{ | |
const ADDR = 'localhost'; | |
const USER = 'showsky'; | |
const PASSWD = ''; | |
const DB = 'object'; | |
private static $db = null; | |
private function __construct(){} | |
public static function instance() | |
{ | |
if(is_null(self::$db)) | |
{ | |
self::$db = new PDO('mysql:dbname='.self::DB.';host='.self::ADDR); | |
} | |
return self::$db; | |
} | |
} | |
abstract class GenericObject | |
{ | |
private $table; | |
private $column; | |
private $id; | |
public function init($table, $id = NULL) | |
{ | |
$this->table = $table; | |
$this->id = $id; | |
if(is_null($id)) throw new Exception('$id it null'); | |
$sql = sprintf("SELECT * FROM `%s` WHERE `id` = '%d'", $table, $id); | |
} | |
public function setColumn($col) | |
{ | |
} | |
public function getColunm($col) | |
{ | |
} | |
public function save() | |
{ | |
} | |
public function destory() | |
{ | |
} | |
} | |
class Book implements GenericObject | |
{ | |
public function __construct() | |
{ | |
$this->init('book',1); | |
} | |
} | |
class User implements GenericObject | |
{ | |
public function __construct() | |
{ | |
$this->init('user',3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Spelling:
destory
-->destroy
?