Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- echo '{"version":"0.3","rows":1}';
- $uri_parts = explode('/', $_SERVER['REQUEST_URI']);
- $file = end($uri_parts);
- $uuid = basename($file,'.json');
- $connection = new \PDO ( 'mysql:host=db;dbname=volkszaehler' , 'vz' , 'vz' , array() );
- $stmt = $connection->prepare('SELECT id FROM entities WHERE uuid = :uuid LIMIT 1' );
- $stmt->bindValue( ':uuid', $uuid);
- $stmt->execute();
- $stmt->setFetchMode( \PDO::FETCH_COLUMN, 0 );
- $channel_id = $stmt->fetch();
- $data = json_decode(file_get_contents('php://input'), true);
- if($channel_id && is_array($data)) {
- $stmt = $connection->prepare('INSERT INTO data (channel_id,timestamp,value) VALUES (:channel_id,:ts,:value)');
- foreach( $data as $single_data ) {
- $stmt->bindValue( ':channel_id', $channel_id);
- $stmt->bindValue( ':ts', $single_data[0]);
- $stmt->bindValue( ':value', $single_data[1]);
- $stmt->execute();
- }
- }
- $connection = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement