PHP量级数据遍历方案:yield生成器-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

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://kswsj.cn/article/jisjjg.html

其他资讯