Skip to content

Instantly share code, notes, and snippets.

@showsky
Created August 12, 2011 05:27
Show Gist options
  • Save showsky/1141518 to your computer and use it in GitHub Desktop.
Save showsky/1141518 to your computer and use it in GitHub Desktop.
classGenericObject
<?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);
}
}
@md2perpe
Copy link

Spelling: destory --> destroy ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment