Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <?php
  2.  
  3. //nawiązywanie połączenia
  4. require_once "connect.php";
  5. mysqli_report(MYSQLI_REPORT_STRICT);
  6.  
  7. try
  8. {
  9. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  10.  
  11. if ($polaczenie->connect_errno!=0)
  12. {
  13. throw new Exception(mysqli_connect_errno());
  14.  
  15. }
  16. else
  17. {
  18. header('Content-Type: application/json; charset=utf8');
  19.  
  20. //fetch table rows from mysql db
  21. $sql = "select * from tbl_employee";
  22. $result = mysqli_query($polaczenie, $sql) or die("Error in Selecting " . mysqli_error($polaczenie));
  23.  
  24.  
  25. //create an array
  26. $emparray = array();
  27. while($row =mysqli_fetch_assoc($result))
  28. {
  29. $emparray[] = $row;
  30. }
  31.  
  32. echo json_encode($emparray);
  33.  
  34. $polaczenie->close();
  35. }
  36.  
  37. }
  38.  
  39.  
  40.  
  41. catch(Exception $e)
  42. {
  43. echo '<span style= "color:red;">Błąd serwera!</span>';
  44. echo '<br/> Informacja developerska: '.$e;
  45.  
  46. }
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement