Guest User

Untitled

a guest
Mar 11th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public $id;
  2. public $username;
  3. public $password;
  4. public $first_name;
  5. public $last_name;
  6.  
  7.  
  8. public static function find_all_users()
  9. {
  10.  
  11. return self::find_this_query("SELECT *FROM users");
  12. }
  13.  
  14.  
  15. public static function find_all_user_by_id($user_id)
  16. {
  17.  
  18. global $database;
  19. $result_set = self::find_this_query("SELECT *FROM users WHERE id='$user_id' LIMIT 1");
  20. $found_user = mysqli_fetch_array($result_set);
  21. return $found_user;
  22. }
  23.  
  24. public static function find_this_query($sql)
  25. {
  26. global $database;
  27. $result_set = $database->query($sql);
  28. $the_object_array = array();
  29. while ($row = mysqli_fetch_assoc($result_set)) {
  30. $the_object_array[] = self::instanation($row);
  31. }
  32. return $the_object_array;
  33.  
  34. }
  35.  
  36. public static function instanation($the_record)
  37. {
  38. $the_object = new self;
  39. /* $the_object->id=$found_user['id'];
  40. $the_object->username= $found_user['username'];
  41. $the_object->password= $found_user['password'];
  42. $the_object->first_name= $found_user['first_name'];
  43. $the_object->last_name= $found_user['last_name'];*/
  44.  
  45. foreach ($the_record as $the_attribute => $value) {
  46. if ($the_object->has_the_attribute($the_attribute)) {
  47.  
  48. $the_object->$the_attribute = $value;
  49. }
  50. }
  51.  
  52. return $the_record;
  53. }
  54.  
  55. private function has_the_attribute($the_attribute)
  56. {
  57. $object_properties = get_object_vars($this);
  58. array_key_exists($the_attribute, $object_properties);
  59.  
  60. }
Add Comment
Please, Sign In to add comment