我有sql自定义执行方法,但发现错误无缓冲查询

i have a class which has custom query execution. Then it shown some error if after i execute that.

SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.

I have search out my problem answer but, almost of them recommend me to put $stmt->closeCursor() in my code, but i have done with it and still get error. The error shown is same with error above. Below is my DBClassification class. Please help me. Thanks :)

<?php
class DBClassification
{
    public $db = null;
    public $host = "localhost";
    public $user = "root";
    private $pass = "";
    public $path = __DIR__ . "\\";
    public $prefixFilename = "klasifikasi_";
    public $dbexception = [];
    public $stmt;

    public function setHost($host){
        $this->host = $host;
    }

    public function setUser($user){
        $this->user = $user;
    }

    public function setPass($pass){
        $this->pass = $pass;
    }

    public function setPath($path)
    {
        if (!is_dir($path)) die ("Directory \$path is not correct!
$path");

        $lastchar = substr($path, -1);
        if ($lastchar != "/" && $lastchar != "\\") $path = $path . "/";
        if (strpos($path, '/') !== false) $path = str_replace("/","\\",$path);

        $this->path = $path . $this->host . "\\"; // setting path to the generated output file
    }

    public function setPrefixFilename($prefixFilename){
        $this->prefixFilename = $prefixFilename;
    }

    public function setDBException($dbexception=[]){
        $this->dbexception = $dbexception;
    }

    public function init($host,$user,$pass,$path,$prefixFilename,$dbexception=[])
    {
        if (!$dbexception) $dbexception = ["information_schema","mysql","performance_schema","phpmyadmin","sys"];
        $this->setHost($host);
        $this->setUser($user);
        $this->setPass($pass);
        $this->setPath($path);
        $this->setPrefixFilename($prefixFilename);
        $this->setDBException($dbexception);
        $this->openConnection();
    }

    // Establishing Connection to mysql database on specified host
    public function openConnection(){
        try {
            $db = new PDO("mysql:host=".$this->host, $this->user, $this->pass);
            $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
            $this->db = $db;
            return true;
        } catch (PDOException $e) {
            die("Error!: " . $e->getMessage());
        }
        return false;
    }
    public function run(){
        try {
            $databases = $this->stmtExec("SHOW DATABASES",true);
            foreach($databases as $database): // execute each database
                $dbname = $database['Database']; // database name
                if(!in_array($dbname,$this->dbexception)): // prevent clasifying dbname which contain in dbexception
                    echo "USE $dbname
";
                    $this->stmtExec("USE $dbname");
                    $tables = $this->stmtExec("SHOW TABLES",true);

                endif; // if(!in_array($dbname,$dbexception)):
            endforeach; // foreach($databases as $database):
        } catch (Exception $e) {
            echo "Something wrong, failed to clasify each database in host " . $this->host . "
";
            die("Error!: ".$e->getMessage());
        }
    }

    public function stmtExec($sql,$fetch=false)
    {
        try {
            $this->stmt = $this->db->prepare($sql);
            if ($fetch) {
                if ($this->stmt->execute()) $return = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
            } else {
                $return = $this->stmt->execute();
            }
            $this->stmt->closeCursor();
        } catch (PDOException $e) {
            $errormsg = "db Error: ". $this->stmt->queryString . PHP_EOL . $e->getMessage();
            $queryFilename = $this->path . "error.txt";
            file_put_contents($queryFilename, $errormsg);
            print_r($errormsg);die();
        }
        return $return;
    }
}

[ANSWERED]

I have found the solution from that, i have to delete false status in pdo attribute "PDO::ATTR_EMULATE_PREPARES". I think it become error because it will check query in prepare method. And query "use $dbname" is one which has no output and will give error if prepare check is on. Thats all my opinion.