大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

PHP量级数据遍历方案:yield生成器

getMessage();
            exit();
        }
        static::$instance->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
    }

    public static function getInstance()
    {
        if (!(static::$instance instanceof \PDO)) {
            new static();
        }
        return static::$instance;
    }

    public static function excuteQuery(string $sql)
    {
        static::$sth = static::$instance->prepare($sql);
        static::$sth->execute();
    }

    //防止实例被克隆
    private function __clone()
    {
    }

    public static function cursor()
    {
        while ($row = static::$sth->fetch(\PDO::FETCH_ASSOC)) {
            yield $row;
        }
    }
}

DB::getInstance();
DB::excuteQuery("select * from bill_info");
foreach (DB::cursor() as $info) {
    echo $info['id'] . PHP_EOL;
}

网站题目:PHP量级数据遍历方案:yield生成器
URL地址:http://dzwzjz.com/article/jisjjg.html
在线咨询
服务热线
服务热线:028-86922220
TOP