Advertisement
Guest User

Untitled

a guest
Sep 18th, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?
  2. echo '{"version":"0.3","rows":1}';
  3.  
  4. $uri_parts = explode('/', $_SERVER['REQUEST_URI']);
  5. $file = end($uri_parts);
  6. $uuid = basename($file,'.json');
  7.  
  8. $connection = new \PDO ( 'mysql:host=db;dbname=volkszaehler' , 'vz' , 'vz' , array() );
  9.  
  10. $stmt = $connection->prepare('SELECT id FROM entities WHERE uuid = :uuid LIMIT 1' );
  11. $stmt->bindValue( ':uuid', $uuid);
  12. $stmt->execute();
  13. $stmt->setFetchMode( \PDO::FETCH_COLUMN, 0 );
  14. $channel_id = $stmt->fetch();
  15. $data = json_decode(file_get_contents('php://input'), true);
  16.  
  17. if($channel_id && is_array($data)) {
  18.         $stmt = $connection->prepare('INSERT INTO data (channel_id,timestamp,value) VALUES (:channel_id,:ts,:value)');
  19.         foreach( $data as $single_data ) {
  20.                 $stmt->bindValue( ':channel_id', $channel_id);
  21.                 $stmt->bindValue( ':ts', $single_data[0]);
  22.                 $stmt->bindValue( ':value', $single_data[1]);
  23.                 $stmt->execute();
  24.         }
  25. }
  26.  
  27. $connection = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement