Guest User

Untitled

a guest
Oct 24th, 2017
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2.  
  3. // Create connection
  4. $con=mysqli_connect("localhost","seemuapp_teacher","P@ssword","seemuapp_students");
  5.  
  6. // Check connection
  7. if (mysqli_connect_errno())
  8. {
  9.   echo "Failed to connect to MySQL: " . mysqli_connect_error();
  10. }
  11.  
  12. // Select all columns from the Classes table
  13. $sql = "SELECT * FROM classes";
  14.  
  15. // Check if there are results
  16. if ($result = mysqli_query($con, $sql))
  17. {
  18.     // If so, then create a results array and a temporary one
  19.     // to hold the data
  20.     $resultArray = array();
  21.     $tempArray = array();
  22.  
  23.     // Loop through each row in the result set
  24.     while($row = $result->fetch_object())
  25.     {
  26.         // Add each row into our results array
  27.         $tempArray = $row;
  28.         array_push($resultArray, $tempArray);
  29.     }
  30.  
  31.     // Finally, encode the array to JSON and output the results
  32.     echo json_encode($resultArray);
  33. }
  34.  
  35. // Close connections
  36. mysqli_close($con);
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment