Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- $db = new PDO("mysql:host=127.0.0.1;port=3306;dbname=geo;charset=utf8", 'root', '');
- $sth = $db->prepare("SELECT id, region_id FROM regions");
- $sth->execute();
- $result = $sth->fetchAll(PDO::FETCH_ASSOC);
- $stmt = $db->prepare("INSERT INTO cities (`region`, `name`) VALUES (:region_id, :name)");
- $stmt->bindParam(':region_id', $region_id);
- $stmt->bindParam(':name', $name);
- $start = 1;
- $end = 83;
- for ($i = $start; $i <= $end; ++$i) {
- $cities = json_decode(file_get_contents('cities/' . $i . '.json'));
- foreach ($cities as $city) {
- $region_id = $i;
- $name = $city;
- $stmt->execute();
- }
- echo 'Region: ' . $i . ': loaded: ' . count($cities) . '<br>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement