initial
This commit is contained in:
27
ltg.php
Normal file
27
ltg.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
ini_set("log_errors", 1);
|
||||
ini_set("error_log", "/var/www/html/work/php-error.log");
|
||||
|
||||
// Connecting, selecting database
|
||||
$dbconn = pg_connect("host=localhost dbname=nws user=nws password=nws")
|
||||
or die('Could not connect: ' . pg_last_error());
|
||||
|
||||
|
||||
$name = file_get_contents('php://input');
|
||||
$arr = json_decode($name,true);
|
||||
file_put_contents('test1.txt', $arr);
|
||||
foreach($arr as $item) { //foreach element in $arr
|
||||
file_put_contents('test3.txt', $item, FILE_APPEND);
|
||||
$dtg = $item['time']; //etc
|
||||
$lat = $item['lat'];
|
||||
$lon = $item['lon'];
|
||||
$mag = $item['mag'];
|
||||
pg_query_params($dbconn,
|
||||
"INSERT INTO ltg (datetime,lat,lon,mag) values ($1, $2, $3, $4) on conflict do nothing",
|
||||
array($dtg,$lat,$lon,$mag)) or die('Query failed: ' . pg_last_error());
|
||||
pg_query("COMMIT");
|
||||
}
|
||||
pg_close($dbconn);
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user