-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcities_lat_lng.php
109 lines (85 loc) · 3.31 KB
/
cities_lat_lng.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
echo '<pre>';
// T3S.SU
//$connection = mysql_connect('localhost', 'root', '');
//$db_name = "t3s";
// T3S.VIDEO
//$connection = mysql_connect('93.127.226.130', 'admin', 'prog');
//$db_name = "t3s";
// T3S.BIZ
$connection = mysql_connect('31.28.169.230', 'gilatrade_t3s', 'agwg856qd!@57');
$db_name = "gilatrade_t3s";
if (!$connection) {
die("Ошибка подключения к БД: ". mysql_error());
}
if (!mysql_select_db($db_name, $connection)) {
die("Ошибка выбора БД ".$db_name.": ". mysql_error());
}
if (!mysql_set_charset('utf8', $connection)) {
die("Ошибка установки charset utf8 для БД ".$db_name.": ". mysql_error());
}
$query = "UPDATE wp_tzs_cities SET lat = NULL, lng = NULL WHERE id IS NOT NULL";
$cursor = mysql_query($query, $connection);
if (!$cursor) {
echo "Обнуление координат - Ошибка: ". mysql_error().'<br/>';
}
else {
echo 'Обнуление координат - OK<br/>';
}
$query = "SELECT * FROM wp_tzs_cities WHERE country_id > 0 AND city_id > 0 AND (lat IS NULL OR lng is NULL)";
echo 'query = '.$query.'<br/>';
$cursor = mysql_query($query, $connection);
if (!$cursor) {
die("Ошибка выполнения запроса ".$query." : ". mysql_error());
}
$upd_array = array();
$key = "dj0yJmk9emc1SWFXZnJ2UUxoJmQ9WVdrOWFESm1abkprTjJVbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1kNQ";
while($row = mysql_fetch_assoc($cursor)) {
$id = $row['city_id'];
$name = $row['title_ru'];
echo $id.'-'.$name.'-';
$url = "http://where.yahooapis.com/v1/place/$id?format=json&lang=ru&appid=$key";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result=curl_exec($ch);
curl_close($ch);
$res = json_decode($result, true);
if (isset($res["error"])) {
echo '- Error: '.$res["error"].'<br/>';
}
else if (!isset($res["place"])) {
echo '- Error: NOT PLACE<br/>';
}
$rec = $res["place"];
$lat = isset($rec["centroid"]) && isset($rec["centroid"]["latitude"])? $rec["centroid"]["latitude"] : NULL;
$lng = isset($rec["centroid"]) && isset($rec["centroid"]["longitude"])? $rec["centroid"]["longitude"] : NULL;
echo ' OK: lat='.$lat.', lng='.$lng.'<br/>';
//$upd_array .= array($row['id'], $lat, $lng);
//$query = "UPDATE wp_tzs_cities SET lat = ".$lat.", lng = ".$lng." WHERE id = ".$row['id'];
$query = "UPDATE wp_tzs_cities SET lat = ". sprintf("%.6F", $lat).", lng = ".sprintf("%.6F", $lng)." WHERE id = ".$row['id'];
$upd_array[$row['id']] = $query;
}
print_r($upd_array);
$count = 0;
foreach ($upd_array as $key => $query) {
echo $key.' - '.$query;
$cursor = mysql_query($query, $connection);
if (!$cursor) {
echo " - Ошибка: ". mysql_error().'<br/>';
}
else {
echo ' - OK<br/>';
$count++;
if ($count > 0) {
//break;
}
}
}
echo '</pre>';