info('task export offline channel-table start'); $exportFile = storage_path('app/public/export/offline/' . $this->argument('db') . '-' . date("Y-m-d") . '.db3'); $dbh = new \PDO('sqlite:' . $exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true)); $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING); $dbh->beginTransaction(); $query = "INSERT INTO channel ( id , name , type , language , summary , owner_id , setting,created_at ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? )"; try { $stmt = $dbh->prepare($query); } catch (\PDOException $e) { Log::error($e->getMessage(), ['exception' => $e]); return 1; } $total = Channel::where('status', 30)->count(); $channels= Channel::where('status', 30) ->select([ 'uid', 'name', 'type', 'lang', 'summary', 'owner_uid', 'setting', 'created_at' ]) ->cursor(); foreach ($channels as $key => $row ) { $currData = array( $row->uid, $row->name, $row->type, $row->lang, $row->summary, $row->owner_uid, $row->setting, $row->created_at, ); $stmt->execute($currData); if($key % 30 ===0){ $precent = (int)($key*100/$total); $this->line("[{$precent}%]"); } } $dbh->commit(); $this->info('task export offline channel-table finished'); return 0; } }