Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if((isset($_REQUEST["ID"]))&&(isset($_REQUEST["Status"]))){
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "arduino_test";
- $jsonarray= array('Status' => false,'Message'=>"Empty" );
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- $jsonarray= array('Status' => false,'Message'=>"Database Not Connected" );
- //echo json_encode($jsonarray);
- }
- else{
- $jsonarray= array('Status'=>True,'Message'=>"Database connected" );
- $sql = "SELECT * FROM `lights` WHERE ID=".$_REQUEST["ID"]."";
- if (($result = $conn->query($sql)) !== FALSE)
- {
- echo "query success";
- $data = array(); //empty array
- while($row = $result->fetch_assoc())
- {
- $jsonarray1[] = $row; //store each row in $data
- }
- //echo json_encode($jsonarray);
- echo json_encode($jsonarray1);
- }
- else
- {
- echo "query failure";
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- //echo json_encode($jsonarray);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement