<?php

namespace Database\Seeders;

use Exception;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class ImportTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        
          
        $db = [
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'host' => env('DB_HOST'),
            'database' => env('DB_DATABASE')
        ];
        
        $country_listSQL = public_path('admin-front/sql/country_list.sql');
        $state_listSQL = public_path('admin-front/sql/state_list.sql');
        $city_listSQL = public_path('admin-front/sql/city_list.sql');

        // exec("mysql --user={$db['username']} --password={$db['password']} --host={$db['host']} --database {$db['database']} < $country_listSQL");
        // exec("mysql --user={$db['username']} --password={$db['password']} --host={$db['host']} --database {$db['database']} < $state_listSQL");
        // exec("mysql --user={$db['username']} --password={$db['password']} --host={$db['host']} --database {$db['database']} < $city_listSQL");

        DB::unprepared(file_get_contents($country_listSQL));
        DB::unprepared(file_get_contents($state_listSQL));
        try{
            DB::unprepared(file_get_contents($city_listSQL));
        }catch(Exception $e){
            Log::info('SQL Import Failed');
        }
        

  
        Log::info('SQL Import Done');
    }
}
