binemmanuel

PHP get all users functions (Buggy)

Sep 21st, 2020
1,043
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getUsers(Object $db): array
  2. {
  3.     // Prepare an SQL Statement.
  4.     // ...
  5.  
  6.     // Bind result values.
  7.     $stmt->bine_result(
  8.         $user['id'],
  9.         $user['name'],
  10.         $user['email']
  11.     );
  12.  
  13.     // Initialize an empty array.
  14.     // This should contain all users.
  15.     $users = [];
  16.  
  17.     // Fetch data.
  18.     while ($stmt->fetch()) {
  19.         array_push($users, $user);
  20.     }
  21.  
  22.     return $users;
  23. }
RAW Paste Data