$found = 0; $hangcheck = 5; $time = microtime(true); while ($row = $res->fetch_row()) { $done++; $bssid = $row[0]; $latitude = 0; $longitude = 0; $quadkey = 'NULL'; $coords = GeoLocateAP(dec2mac($bssid)); if ($coords != '') { $found++; $coords = explode(';', $coords); $latitude = (double) $coords[0]; $longitude = (double) $coords[1]; $quadkey = base_convert(latlon_to_quadkey($latitude, $longitude, MAX_ZOOM_LEVEL), 2, 10); } QuerySql("UPDATE GEO_TABLE SET `latitude`={$latitude},`longitude`={$longitude}, `quadkey`={$quadkey} WHERE `BSSID`={$bssid}"); if (microtime(true) - $time > $hangcheck && $done < $total) { logt("Status: {$done} of {$total}, {$found} found on map (Working)"); $time = microtime(true); } } logt("Status: {$done} of {$total}, {$found} found on map (Done!)"); } $res->close(); sleep(10); } break; // Обновление ранее не найденных точек // Обновление ранее не найденных точек
db_connect(); foreach (array('geo', 'mem_geo') as $geo_table) { $sql = "ALTER TABLE `{$geo_table}` \n\t\t\tADD COLUMN `quadkey` BIGINT(20) UNSIGNED DEFAULT NULL, \n\t\t\tDROP INDEX `Coords`, \n\t\t\tADD INDEX (`quadkey`)"; var_dump($sql); if (!$db->query($sql)) { echo "Failed to alter table {$geo_table}: "; echo "(" . $db->errno . ") " . $db->error; } $coord_res = QuerySql("SELECT * FROM {$geo_table} \n\t\t\tWHERE `latitude` != 0 AND `longitude` != 0 \n\t\t\tAND `latitude` IS NOT NULL AND `longitude` IS NOT NULL \n\t\t\tAND `quadkey` IS NULL"); if (!$coord_res) { echo "Failed to select from {$geo_table}: "; echo "(" . $db->errno . ") " . $db->error; exit; } if (!($stmt = $db->prepare("UPDATE {$geo_table} SET `quadkey`=? WHERE `BSSID`=?"))) { echo "Failed to prepare query: (" . $db->errno . ") " . $db->error; exit; } $quadkey = ''; $bssid = ''; if (!$stmt->bind_param("ss", $quadkey, $bssid)) { echo "Failed to bind params: (" . $stmt->errno . ") " . $stmt->error; exit; } while ($coord_row = $coord_res->fetch_row()) { $bssid = $coord_row[0]; $quadkey = base_convert(latlon_to_quadkey($coord_row[1], $coord_row[2], MAX_ZOOM_LEVEL), 2, 10); $stmt->execute(); } $stmt->close(); }