首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从PDOStatement获取PDO

从PDOStatement获取PDO
EN

Stack Overflow用户
提问于 2014-12-01 21:22:01
回答 1查看 132关注 0票数 1

请考虑以下几点:

代码语言:javascript
复制
$PDOStatement = $PDO->prepare($query);

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-01 22:03:45

目前这是不可能的。即使PDOStatement的每个实例都存储一个用来创建它的DB句柄(引用lxr for PHP5.6):

代码语言:javascript
复制
/* 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 (链接)的引用:

代码语言:javascript
复制
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;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27237563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档