网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

laravelcursor的底层实现

foreach(BillInfo::where('id','>',0)->orderBy('id','desc')->limit(10000)->cursor()as$value) {
   print_r($value);
}

创新互联建站专注于李沧企业网站建设,成都响应式网站建设公司,商城网站定制开发。李沧网站建设公司,为李沧等地区提供建站服务。全流程按需制作网站,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务

Illuminate\Database\Query\Builder.php;
/**
* Get a generator for the given query.
*
*@return\Generator
*/
public functioncursor()
{
   if(is_null($this->columns)) {
       $this->columns= ['*'];
   }

   return$this->connection->cursor(
       $this->toSql(),$this->getBindings(), !$this->useWritePdo
   );
}

Illuminate\Database\Connection.php;
/**
* Run a select statement against the database and returns a generator.
*
*@param  string  $query
*@param  array  $bindings
*@param  bool  $useReadPdo
*@return\Generator
*/
public functioncursor($query,$bindings= [],$useReadPdo=true)
{
   $statement=$this->run($query,$bindings,function($query,$bindings)use($useReadPdo) {
       if($this->pretending()) {
           return[];
       }

       // First we will create a statement for the query. Then, we will set the fetch
       // mode and prepare the bindings for the query. Once that's done we will be
       // ready to execute the query against the database and return the cursor.
       $statement=$this->prepared($this->getPdoForSelect($useReadPdo)
                         ->prepare($query));

       $this->bindValues(
           $statement,$this->prepareBindings($bindings)
       );

       // Next, we'll execute the query against the database and return the statement
       // so we can return the cursor. The cursor will use a PHP generator to give
       // back one row at a time without using a bunch of memory to render them.
       $statement->execute();

       return$statement;
   });

   while($record=$statement->fetch()) {
       yield$record;
   }
}

当前文章:laravelcursor的底层实现
分享地址:http://bjjierui.cn/article/ppggoj.html

其他资讯