Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ((isset($_GET['method'])) && !empty($_GET['method']))
- {
- if (function_exists($_GET['method']))
- {
- $_GET['method']();
- }
- }
- function getAllUsers()
- {
- $serverName = 'localhost'; //Variables to access the database
- $username = '';
- $password = '';
- $database = '';
- $conn = mysqli_connect($serverName, $username, $password, $database); //Connect to the database
- if(!$conn) //If the database failed to connect
- {
- die("Database failed to connect: " .mysqli_connect_error()); //Display an error message
- }
- $users = [];
- $sql = "SELECT * FROM users"; //Select all users
- $stmt = $conn->prepare($sql);
- $stmt->execute(); //Execute the query
- $result = $stmt->get_result();
- while($row = $result->fetch_assoc()) //For every user
- {
- $userInfo = [];
- array_push($userInfo, $row['user_id']);
- array_push($userInfo, $row['username']);
- array_push($userInfo, $row['moderator']);
- array_push($userInfo, $row['bio']);
- array_push($userInfo, $row['kills']);
- array_push($userInfo, $row['deaths']);
- array_push($userInfo, $row['score']);
- array_push($users, $userInfo);
- }
- $users = json_encode($users);
- echo $_GET ['jsoncallback'] . '(' . $users . ')';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement