【发布时间】:2011-11-19 20:01:29
【问题描述】:
我已经阅读了很多这方面的例子,但是我读的越多,我就越感到困惑(对不起!)。我的首要任务是保持简单和高效。生成单个 MySql 连接并与多个 PHP 对象共享。
// open a db connection
$dbc = new PDO(.......);
// allow multiple objects to use the same connection
$object_1 = new class_1($dbc);
$object_2 = new class_2($dbc);
$object_3 = new class_3($dbc);
// or should it be passed this way?
$object_1->connection($dbc);
$object_2->connection($dbc);
$object_3->connection($dbc);
// or should each of the classes be getting the connection
// from a singleton type db object?
// should each object be an extesion of a db class?
// or is there something else I need to consider?
【问题讨论】:
标签: php oop dependency-injection pdo