एक सरल विधि को लागू करने के लिए आप की तरह हो सकता आरंभ करने के लिए:
class db
{
public function __call($function, $arguments)
{
switch($function) {
// implement table handling here
case 'user':
//do something
return $something;
break;
}
}
}
या नहीं, आप जटिल है, लेकिन ठोस या साधारण जाना चाहता हूँ पर निर्भर करता है, लेकिन कम सुविधाजनक आप दो अलग अलग रणनीतियों को लागू कर सकते हैं। सरल रणनीति इसलिए की तरह जा सकते हैं:
class db
{
protected $operatingTable;
public function limit($limitNumber)
{
return $this->executeQuery("SELECT * FROM ".$this->operatingTable." LIMIT ".$limitNumber); // where executeQuery is a function that runs a query
}
public function __call($function, $arguments)
{
switch($function) {
// implement table handling here
case 'user':
$this->operatingTable='user'; // alternately, but less secure: $this->operatingTable=$function;
return $this;
break;
}
}
}
वैकल्पिक रूप से, लेकिन अधिक शक्तिशाली:
class db
{
protected $operatingTable;
public function limit($limitNumber)
{
return $this->executeQuery("SELECT * FROM ".$this->operatingTable." LIMIT ".$limitNumber); // where executeQuery is a function that runs a query
}
public function __call($function, $arguments)
{
switch($function) {
// implement table handling here
case 'user':
$user = new user($this); // pass in the database to the object, so the table object can have a reference to the db
return $user;
break;
}
}
}
class baseTableClass
{
protected $db; // an instance of class db
function limit($limitNumber)
{
$db->execute($aStatementDerivedFromThisClassesInformation); // execute a sql command, based on information about the table in the class
}
}
class user extends baseTableClass
{
public function __construct($db) {
$this->db = $db;
}
}
आप अंदाजा हो। या तो ओवरलोड डाटाबेस वस्तु, या एक आधार डाटाबेस वस्तु बनाने, और तालिका वस्तुओं, टेबल वस्तुओं में बुद्धि के बहुत डाल, यह सुनिश्चित करना कि जब बनाया, एक मेज वस्तु भंडार db ऑब्जेक्ट के संदर्भ
Dude यह है ** श्रृंखलन **, घोंसला नहीं। – Pacerier