私はPDOを使用するのがとても好きなので、オンになっている可能性があります。
使用法は次のようになります。
$m = new MDB();
$m->Users()->GetRec($param);
Users()
データベース内のテーブルの名前であり、GetRec($param)
私の関数です。
私がこのように見えるようにする方法:
class MDB extends DB {
function __construct(){
parent::__construct();
if ($result = $this->pdo->query("SHOW TABLES"))
{
while ($row = $result->fetch(PDO::FETCH_NUM))
{
// this is only my imagination (not working at all)
__set($row[0],true);
}
}
}
// set
public function __set($name, $value)
{
// here could be a method (not properties)
$this->$name = $value;
}
確かに、それはすべて私が望んでいるものではないようです。だから私はこの質問でいくつかの提案やアドバイスを得ることができます。
upd1。
魔法のメソッド__callをありがとう、そして今私はそれを内に作ろうとしています。私の更新されたコードを見てください:
class MDB extends DB {
function __construct(){
parent::__construct();
}
public function __call( $method, $param )
{
$tables = array();
if ($result = $this->pdo->query("SHOW TABLES"))
{
while ($row = $result->fetch(PDO::FETCH_NUM))
{
$tables[] = $row[0];
}
}
if (in_array($method,$tables))
{
return $this;
}
else
{
return FALSE;
}
}
まあ、それは私のために働くようです!