mikroavr

mysql_adapter_power_meter

Jan 31st, 2021 (edited)
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. <?php
  2.     $json = file_get_contents('php://input');
  3.     echo $json;
  4.     $data = json_decode($json);
  5.  
  6.     $ctlr_id = $data->ctlr_id;
  7.     $auth = $data->auth;
  8.     $kwh_id = $data->kwh_id;
  9.     $kwh_type =$data->kwh_type;
  10.     $type_kwh_code = $data->type_kwh_code;
  11.    
  12.     $va = (float)$data->va;
  13.     $vb = (float)$data->vb;
  14.     $vc = (float)$data->vc;
  15.  
  16.     $ia = (float)$data->ia;
  17.     $ib = (float)$data->ib;
  18.     $ic = (float)$data->ic;
  19.  
  20.     $pf = (float)$data->pf;
  21.     $f = (float)$data->f;
  22.     $kwh = (float)$data->kwh;
  23.     $_ts = $data->ts;
  24.     $time = strtotime($_ts);
  25.     $ts = date("Y-m-d H:i:s", $time);
  26.    
  27.     $servername = "localhost";
  28.     $username = "root";
  29.     $password = "";
  30.     $dbName = "pantaukwh";
  31.  
  32. // Create connection
  33.     $conn = mysqli_connect($servername, $username, $password, $dbName);
  34.  
  35. // Check connection
  36.   if (!$conn) {
  37.     die("Connection failed: " . mysqli_connect_error());
  38.     }
  39.    
  40.     $sql = "INSERT INTO pm05 (ctlr_id, auth, kwh_id, kwh_type, type_kwh_code, va, vb, vc, ia, ib, ic, pf, f, kwh, ts)
  41. VALUES ('$ctlr_id', '$auth', '$kwh_id', '$kwh_type', '$type_kwh_code', '$va', '$vb', '$vc', '$ia', '$ib', '$ic', '$pf', '$f', '$kwh', '$ts')";
  42.     if (mysqli_query($conn, $sql)) {
  43.         echo "New record created successfully";
  44.       } else {
  45.         echo "Error: " . $sql . "<br>" . mysqli_error($conn);
  46.       }
  47.      
  48.       mysqli_close($conn);
  49.  
  50.      
  51. ?>
  52.  
Add Comment
Please, Sign In to add comment