Php 从PDO语句获取PDO

Php 从PDO语句获取PDO,php,pdo,Php,Pdo,考虑以下几点: $PDOStatement = $PDO->prepare($query); 是否可以从$PDO语句实例中获取$PDO实例?目前,这是不可能的。即使PDO语句的每个实例都存储一个用于创建它的DB句柄(): 。。。它不是通过公共方法公开的 值得注意的是,pdo_dbh_t实例反过来可能(至少看起来是这样)存储对pdo_stm_t()的引用: var_dump($PDOStatement)将显示statement对象中的任何反向链接。的文档似乎没有显示任何方法。请问你为什么

考虑以下几点:

$PDOStatement = $PDO->prepare($query);

是否可以从
$PDO语句
实例中获取
$PDO
实例?

目前,这是不可能的。即使PDO语句的每个实例都存储一个用于创建它的DB句柄():

。。。它不是通过公共方法公开的


值得注意的是,
pdo_dbh_t
实例反过来可能(至少看起来是这样)存储对
pdo_stm_t
()的引用:


var_dump($PDOStatement)
将显示statement对象中的任何反向链接。的文档似乎没有显示任何方法。请问你为什么要这样做?你想解决的实际问题是什么?很小。我正在编写的类既需要
PDO语句
实例,也需要生成它的
PDO
实例。我想知道我是否可以简化这个类的接口。看起来你做不到。@raina77ow,你应该写这个作为答案。
/* represents a prepared statement */
543 struct _pdo_stmt_t {
544    /* these items must appear in this order at the beginning of the
545       struct so that this can be cast as a zend_object.  we need this
546       to allow the extending class to escape all the custom handlers
547       that PDO declares.
548    */
549    zend_object std;
550
...
572    /* we want to keep the dbh alive while we live, so we own a reference */
573    zval database_object_handle;
574    pdo_dbh_t *dbh;
427 /* represents a connection to a database */
428 struct _pdo_dbh_t {
... 
501    /* when calling PDO::query(), we need to keep the error
502     * context from the statement around until we next clear it.
503     * This will allow us to report the correct error message
504     * when PDO::query() fails */
505    pdo_stmt_t *query_stmt;