【发布时间】:2011-03-03 08:26:47
【问题描述】:
我想继承 PDOStatement 类并在我的网站脚本中使用它。
但我很沮丧如何获得所需的对象。 PDO::query 只返回直接 PDOStatement 对象,看起来没有其他方法可以创建 PDOStatement 对象或继承类。
最初我想将 PDOStatement 对象移动到继承类的构造函数 类似的东西:
$stmt = PDO -> query("select * from messages");
$messageCollection = new Messaging_Collection($stmt);
但是如何使 PDOStatement 的实例成为继承对象(Messaging_Collection)。这对我来说是个大问题。
class Messaging_Collection extends PDOStatement
{
public function __construct(PDOStatement $stmt)
{
//there i should to transform $stmt to $this
// direct $this = $stmt is not possible
// is there other right way?
}
【问题讨论】:
标签: php oop pdo pdostatement