-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadDataToSQLBackup.php
57 lines (40 loc) · 1.34 KB
/
LoadDataToSQLBackup.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
<?php
try
{
$conn = new PDO("sqlsrv:Server=DESKTOP-BLQ3M1P\SQLEXPRESS;Database=Limburg");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
die (print_r($e->getMessage()));
}
// $tsql = "SELECT * FROM dbo.Route";
// $getResults = $conn->prepare($tsql);
// $getResults->execute();
// $results = $getResults->fetchAll(PDO::FETCH_BOTH);
// foreach($results as $row) {
// echo $row['Height'];
// echo '<br>';
// }
$string = file_get_contents("http://127.0.0.1/test/Tile%20(5_5).json");
$json_a = json_decode($string, true);
$coord = "_x".$json_a['X']."_y".$json_a['Y'];
$tsql = "CREATE TABLE [".$coord."]([height] [float] NULL) ON [PRIMARY]";
$runSQLCreateTable = $conn->prepare($tsql);
$runSQLCreateTable->execute();
//$counter = 0;
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($string, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val) {
if(!is_array($val) && is_float($val)) {
$query = "INSERT [".$coord."] ([height]) VALUES (".$val.")";
$runSQLAddData = $conn->prepare($query);
$runSQLAddData->execute();
} else{
//echo "$key => $val\n";
}
}
//echo "number of numbers: $counter";
echo $tsql;
?>