Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2.     set_time_limit(0);
  3.     $db = new PDO("mysql:host=127.0.0.1;port=3306;dbname=geo;charset=utf8", 'root', '');
  4.     $sth = $db->prepare("SELECT id, region_id FROM regions");
  5.     $sth->execute();
  6.  
  7.     $result = $sth->fetchAll(PDO::FETCH_ASSOC);
  8.  
  9.     $stmt = $db->prepare("INSERT INTO cities (`region`, `name`) VALUES (:region_id, :name)");
  10.     $stmt->bindParam(':region_id', $region_id);
  11.     $stmt->bindParam(':name', $name);
  12.  
  13.     $start = 1;
  14.     $end = 83;
  15.     for ($i = $start; $i <= $end; ++$i) {
  16.         $cities = json_decode(file_get_contents('cities/' . $i . '.json'));
  17.         foreach ($cities as $city) {
  18.             $region_id = $i;
  19.             $name = $city;
  20.             $stmt->execute();
  21.         }
  22.         echo 'Region: ' . $i . ': loaded: ' . count($cities) . '<br>';
  23.     }
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement