_______________________________________________________________________
S.A.R.L au capital de 500 100 Euro Siret : 444.396.519.00027 APE : 4669A TVA intracom : FR-35444.396.519
Annex 1: PHP file example (Private server)
<?php
/***********************************/
/* CHANGE THESE PARAMETERS */
/***********************************/
$host
=
"localhost"
;
$login
=
"db-login"
;
$psw
=
"db-password"
;
$database
=
"db-name"
;
$port
=
"3306"
;
/***********************************/
/* CHANGE NOTHING BELOW THIS LINE */
/***********************************/
$queryCreateUsersTableFirstPart
=
"CREATE TABLE IF NOT EXISTS `"
;
$queryCreateUsersTableSecPart
=
"` (
`Index` int(255) NOT NULL AUTO_INCREMENT,
`ID` varchar(10) CHARACTER SET ascii NOT NULL,
`Location` varchar(60) CHARACTER SET ascii NOT NULL,
`TimeDate` datetime NOT NULL,
`Value` float NOT NULL,
PRIMARY KEY (`Index`)
) ENGINE=InnoDB"
;
/* create a connection */
$mysqli
=
new
mysqli(
$host
,
$login
,
$psw
,
$database
,
$port
);
/* check connection */
if
(mysqli_connect_errno()) {
printf(
"Connect failed: %s
\n
"
, mysqli_connect_error());
exit();
}
/* grabbing from an HTTP GET or HTTP POST */
$json
= file_get_contents(
"php://input"
);
/* use json_decode to create object from json */
$json_o
=json_decode(
$json
);
/* object method /*
foreach
(
$json_o
->datastreams
as
$DataStream
)
{
/* parse first values */
$table
=
$DataStream
->alias;
$Location
=
$DataStream
->location;
$Id
=
$DataStream
->id;
/* create table if not exist */
$mysqli
-
>query(
$queryCreateUsersTableFirstPart
.
$table
.
$queryCreateUsersTableSecPart
);
/* fill in the table */
foreach
(
$DataStream
->datapoints
as
$DataPoints
)
{
$mysqli
->query(
"INSERT INTO `"
.
$table
.
"` (`Index` ,`ID` ,`Location`
,`TimeDate` ,`Value`)VALUES (NULL , '"
.
$Id
.
"', '"
.
$Location
.
"', '"
.
$DataPoints
-
>at.
"', '"
.
$DataPoints
->value.
"')"
);
}
}
/* close connection */
$mysqli
->close();
?>