<?php/** * Created by Phpstorm. * USER:ZRJ * date:18-6-22 * time: Morning 10:49 */declare (Strict_types=1);//Open strongly typed mode class db{private static $instance = null; private static $sth = null; Private Function __construct () {try {$dsn = "mysql:host=192.168.1.9;dbname=yundou_v3"; static:: $instance = new \pdo ($dsn , ' user ', ' password '); } catch (Pdoexception $e) {echo ' Connection failed: '. $e->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; The public static function Excutequery (string $sql) {static:: $sth = static:: $instance->prepare ($sql); Static:: $sth- >execute (); }//Prevents the instance from being cloned private function __clone () {} public static function cursor () {while ($row = static:: $sth->fetch (\pdo::fe TCH_ASSOC) {yield $row;}}} Db::getinstance ();D b::excutequery ("SELECT * from Bill_info"); foreach (Db::cursor () as $info{echo $info [' ID ']. Php_eol;}
PHP Scale Data traversal scenario: Yield generator