dorv56831 2017-09-15 13:50
浏览 224

PHP PDO不能关闭连接

I have an code with PHP PDO which close the connections. Like this: PDO closing connection

But in mysql workbench the counter of total connections doesn't decrease. Every time I refresh the site the connections is counted up and will no descrease after that.

I have set already wait_timeout and interactive_timeout to 5 but nothing happened.

[EDIT]

class DatabaseFactory {
    private static $factory;
    private $connection = array(
        "DB_HOST" => "localhost",
        "DB_PASS" => "************",
        "DB_USER" => "************",
        "DB_PORT" => "3306",
        "DB_CHARSET" => "utf8"
    );

    public static function getFactory() {
        if(!self::$factory) {
            self::$factory = new DatabaseFactory();
        }
        return self::$factory;
    }

    private $db;

    public function getconnection($name) {
        echo "opened";
        try {
            $options = array(
                \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ,
                \PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING
            );
            $this->db = new \PDO('mysql:host='.$this->connection["DB_HOST"].';dbname='.$name.';port=' .$this->connection["DB_PORT"].';charset='.$this->connection["DB_CHARSET"], $this->connection["DB_USER"], $this->connection["DB_PASS"], $options);
        } catch (PDOException $e) {
            exit($e->getMessage());
        }
        return $this->db;
    }

    static function closeConnection(&$conn) {
        echo "closed";
        $conn = null;
    }
}

$database = DatabaseFactory::getFactory()->getconnection("Admin");
$query = $database->prepare("SELECT * FROM tester WHERE t_u_id = :u_id");
$query->execute(array(":u_id" => "281123341528-D050C4-91A0BA-1CB0C8-8112334152855AC373"));
var_dump($query->fetch());
DatabaseFactory::closeConnection($database);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器