| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Storage;
- class ExportCreateDb extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'export:create.db';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- $sqlPath = database_path('export/sentence.sql');
- $exportFile = storage_path('app/public/export/offline/sentence-'.date("Y-m-d").'.db3');
- $file = fopen($exportFile,'w');
- fclose($file);
- $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
- $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
- //建立数据库
- $_sql = file_get_contents($sqlPath);
- $_arr = explode(';', $_sql);
- //执行sql语句
- foreach ($_arr as $_value) {
- $dbh->query($_value . ';');
- }
- return 0;
- }
- }
|