From 8b7f5831ffa284eee1c8f9760971b13b5ce619e0 Mon Sep 17 00:00:00 2001 From: Stephen Lake Date: Thu, 13 Sep 2018 06:46:30 +0200 Subject: [PATCH] Fix #6 for both mysql and postgres - my mistake :poop: --- src/commands/seedGeoFile.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/commands/seedGeoFile.php b/src/commands/seedGeoFile.php index 79e5fae..ed7a8ff 100644 --- a/src/commands/seedGeoFile.php +++ b/src/commands/seedGeoFile.php @@ -11,9 +11,14 @@ class seedGeoFile extends Command protected $description = 'Load + Parse + Save to DB a geodata file.'; private $pdo; + private $driver; public function __construct() { parent::__construct(); + + $connection = config('database.default'); + $this->driver = strtolower(config("database.connections.{$connection}.driver")); + $this->pdo = \DB::connection()->getPdo(\PDO::FETCH_ASSOC); if (!\Schema::hasTable('geo')) return; @@ -139,7 +144,12 @@ public function handle() { // Store Tree in DB $this->info("Writing in Database"); - $stmt = $this->pdo->prepare("INSERT INTO geo (\"id\", \"parent_id\", \"left\", \"right\", \"depth\", \"name\", \"alternames\", \"country\", \"level\", \"population\", \"lat\", \"long\") VALUES (:id, :parent_id, :left, :right, :depth, :name, :alternames, :country, :level, :population, :lat, :long)"); + + if ($this->driver == 'mysql') { + $stmt = $this->pdo->prepare("INSERT INTO geo (`id`, `parent_id`, `left`, `right`, `depth`, `name`, `alternames`, `country`, `level`, `population`, `lat`, `long`) VALUES (:id, :parent_id, :left, :right, :depth, :name, :alternames, :country, :level, :population, :lat, :long)"); + } else { + $stmt = $this->pdo->prepare("INSERT INTO geo (\"id\", \"parent_id\", \"left\", \"right\", \"depth\", \"name\", \"alternames\", \"country\", \"level\", \"population\", \"lat\", \"long\") VALUES (:id, :parent_id, :left, :right, :depth, :name, :alternames, :country, :level, :population, :lat, :long)"); + } $count = 0; $totalCount = count($this->geoItems->items);