致命错误:调用未定义的方法PDO :: close() [英] Fatal error: Call to undefined method PDO::close()

查看:129
本文介绍了致命错误:调用未定义的方法PDO :: close()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个错误,内容是这样的:

I have got that error and the line was this:

public function __destruct() {
        $this->db->close();
    }

我使用PDO,这是问题所在,PDO驱动程序不识别此功能吗?如果可以,那么PDO中的等效值是什么?

I use PDO, is this the problem, does the PDO driver not recognize this function? If yes, what is its equivalent in PDO?

推荐答案

PDO连接被销毁其对象:

该连接在该PDO对象的生存期内保持活动状态.要关闭连接,您需要通过确保删除所有剩余的对该对象的引用来销毁该对象,方法是将NULL分配给保存该对象的变量.如果您未明确执行此操作,则PHP将在脚本结束时自动关闭连接.

The connection remains active for the lifetime of that PDO object. To close the connection, you need to destroy the object by ensuring that all remaining references to it are deleted--you do this by assigning NULL to the variable that holds the object. If you don't do this explicitly, PHP will automatically close the connection when your script ends.

如此

$this->db = null;

应该工作.

这篇关于致命错误:调用未定义的方法PDO :: close()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆