请考虑以下几点:
$PDOStatement = $PDO->prepare($query);是否可以从$PDO实例中获取$PDOStatement实例?
发布于 2014-12-01 22:03:45
目前这是不可能的。即使PDOStatement的每个实例都存储一个用来创建它的DB句柄(引用lxr for PHP5.6):
/* 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;..。它不是通过公开的方法暴露的。
值得注意的是,pdo_dbh_t实例可以(至少看起来是这样)存储对pdo_stmt_t (链接)的引用:
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;https://stackoverflow.com/questions/27237563
复制相似问题