Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.92 KB | None | 0 0
  1. <?php
  2.  
  3.         $server="localhost";
  4.         $user="root";
  5.         $pass="";
  6.  
  7.         if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  8.         $ip = $_SERVER['HTTP_CLIENT_IP'];
  9.     } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  10.         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  11.     } else {
  12.         $ip = $_SERVER['REMOTE_ADDR'];
  13.             }
  14.  
  15.         $device_id = $_SERVER ['HTTP_USER_AGENT'];
  16.  
  17.         $dbh = new PDO("mysql:host=$server;dbname=weather_station",$user,$pass);
  18.  
  19. $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
  20.  
  21.  
  22. $stmt = $dbh->prepare("INSERT INTO weather_station_bot (id, ip, device_id, temperature, humidity, rain, wind_speed, wind_speed_raw, wind_direction, pressure, uv, tilt, vin, count, elapsed_time, ethernet_error_count, chip_temp, box_temp, smog, version, error_num, error_msg, deleted_at, created_at, updated_at)
  23. VALUES (:id, :ip, :device_id, :temperature, :humidity, :rain, :wind_speed, :wind_speed_raw,: wind_direction, :pressure, :uv, :tilt, :vin, :count, :elapsed_time, :ethernet_error_count, :chip_temp, :box_temp, :smog, :version, :error_num, :error_msg, :deleted_at, :created_at, :updated_at)");
  24.  
  25. $stmt->bindParam(':id', $id);
  26. $stmt->bindParam(':ip', $ip);
  27. $stmt->bindParam(':device_id', $device_id);
  28. $stmt->bindParam(':temperature', $temperature);
  29. $stmt->bindParam(':humidity', $humidity);
  30. $stmt->bindParam(':rain', $rain);
  31. $stmt->bindParam(':wind_speed', $wind_speed);
  32. $stmt->bindParam(':wind_speed_raw', $wind_speed_raw);
  33. $stmt->bindParam(':wind_direction', $wind_direction);
  34. $stmt->bindParam(':pressure', $pressure);
  35. $stmt->bindParam(':uv', $uv);
  36. $stmt->bindParam(':tilt', $tilt);
  37. $stmt->bindParam(':vin', $vin);
  38. $stmt->bindParam(':count', $count);
  39. $stmt->bindParam(':elapsed_time', $elapsed_time);
  40. $stmt->bindParam(':ethernet_error_count', $ethernet_error_count);
  41. $stmt->bindParam(':chip_temp', $chip_temp);
  42. $stmt->bindParam(':box_temp', $box_temp);
  43. $stmt->bindParam(':smog', $smog);
  44. $stmt->bindParam(':version', $version);
  45. $stmt->bindParam(':error_num', $error_num);
  46. $stmt->bindParam(':error_msg', $error_msg);
  47. $stmt->bindParam(':deleted_at', $deleted_at);
  48. $stmt->bindParam(':created_at', $created_at);
  49. $stmt->bindParam(':updated_at', $updated_at);
  50.  
  51. $id=$_POST["id"];
  52. $temperature=$_POST["temperature"];
  53. $humidity=$_POST["humidity"];
  54. $rain=$_POST["rain"];
  55. $wind_speed=$_POST["wind_speed"];
  56. $wind_speed_raw=$_POST["wind_speed_raw"];
  57. $wind_direction=$_POST["wind_direction"];
  58. $pressure=$_POST["pressure"];
  59. $uv=$_POST["uv"];
  60. $vin=$_POST["vin"];
  61. $tilt=$_POST["tilt"];
  62. $count=$_POST["count"];
  63. $elapsed_time=$_POST["elapsed_time"];
  64. $ethernet_error_count=$_POST["ethernet_error_count"];
  65. $chip_temp=$_POST["chip_temp"];
  66. $box_temp=$_POST["box_temp"];
  67. $smog=$_POST["smog"];
  68. $version=$_POST["version"];
  69. $error_num=$_POST["error_num"];
  70. $error_msg=$_POST["error_msg"];
  71. $deleted_at=$_POST["deleted_at"];
  72. $created_at=$_POST["created_at"];
  73. $updated_at=$_POST["updated_at"];
  74.  
  75. $stmt->execute();
  76.                 echo "New record";
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement