-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegionImport.php
More file actions
56 lines (45 loc) · 1.94 KB
/
RegionImport.php
File metadata and controls
56 lines (45 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
//request params
//$countryId = 1; // Russia
$lang = 0; // russian
$headerOptions = array(
'http' => array(
'method' => "GET",
'header' => "Accept-language: en\r\n" .
"Cookie: remixlang=$lang\r\n"
)
);
$methodUrlGetCountry='http://api.vk.com/method/database.getCountries?v=5.27&need_all=1&code=RU&offset=0&count=1';
$streamContext = stream_context_create($headerOptions);
$json = file_get_contents($methodUrlGetCountry, false, $streamContext);
$requestResult=json_decode($json, true);
$countryId=$requestResult['response']['items'][0]['id'];
$methodUrlGetRegions = 'http://api.vk.com/method/database.getRegions?v=5.27&need_all=1&offset=0&count=2&country_id=' . $countryId;
$json = file_get_contents($methodUrlGetRegions, false, $streamContext);
$requestResult = json_decode($json, true);
$regions=$requestResult['response']['items'];
//echo 'CountryId:'.$countryId.' Total regions count: ' . $requestResult['response']['count'] . ' loaded: ' . count($requestResult['response']['items']);
//connection to bd
$mysqli = new mysqli("localhost", "root","root","devstudyqa2", 3306);
if (mysqli_connect_errno()) {
printf("Не удалось подключиться: %s\n", mysqli_connect_error());
exit();
}
$mysqli->set_charset("utf8");
$stmt = $mysqli->prepare("INSERT INTO region (region_id, region_name,region_country_id) VALUES(?,?,?) ");
$affected_rows=0;
$marker = $stmt->param_count;
printf("В запросе %d меток\n", $marker);
foreach ($regions AS $region){
echo'insert params'.$region['id'].' '.$region['title'].' '.$countryId;
$stmt->bind_param('isi',$region['id'],$region['title'],$countryId);
$r=$stmt->execute();
if($r){
echo 'true';
}else{
echo 'false';
}
$affected_rows+=$stmt->affected_rows;
}
echo 'Вставлено строк '.$affected_rows;
//echo 'Total regions count: ' . $arr['response']['count'] . ' loaded: ' . count($arr['response']['items']);