Advertisement
Guest User

Untitled

a guest
Feb 15th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2.  
  3. if ((isset($_GET['method'])) && !empty($_GET['method']))
  4. {
  5. if (function_exists($_GET['method']))
  6. {
  7. $_GET['method']();
  8. }
  9. }
  10.  
  11. function getAllUsers()
  12. {
  13. $serverName = 'localhost'; //Variables to access the database
  14. $username = '';
  15. $password = '';
  16. $database = '';
  17.  
  18. $conn = mysqli_connect($serverName, $username, $password, $database); //Connect to the database
  19.  
  20. if(!$conn) //If the database failed to connect
  21. {
  22. die("Database failed to connect: " .mysqli_connect_error()); //Display an error message
  23. }
  24.  
  25. $users = [];
  26. $sql = "SELECT * FROM users"; //Select all users
  27. $stmt = $conn->prepare($sql);
  28. $stmt->execute(); //Execute the query
  29.  
  30. $result = $stmt->get_result();
  31.  
  32.  
  33. while($row = $result->fetch_assoc()) //For every user
  34. {
  35. $userInfo = [];
  36.  
  37. array_push($userInfo, $row['user_id']);
  38. array_push($userInfo, $row['username']);
  39. array_push($userInfo, $row['moderator']);
  40. array_push($userInfo, $row['bio']);
  41. array_push($userInfo, $row['kills']);
  42. array_push($userInfo, $row['deaths']);
  43. array_push($userInfo, $row['score']);
  44.  
  45. array_push($users, $userInfo);
  46. }
  47.  
  48. $users = json_encode($users);
  49. echo $_GET ['jsoncallback'] . '(' . $users . ')';
  50. }
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement