Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. class Account {
  2. private $db;
  3. private $db_id;
  4. public $id_number, $first_name, $middle_name, $last_name, $age, $password, $picture;
  5.  
  6. public function __construct($db) {
  7. $this->db = $db;
  8. }
  9.  
  10. public function createAccount($id_number = '', $first_name = '', $middle_name = '', $last_name = '', $age = '', $password = '', $picture = '') {
  11. $result = $this->db->query("select a_id from accounts where a_id_number = ?", $id_number)->fetchArray();
  12. print_r($result);
  13.  
  14. if (!isset($result['a_id'])) {
  15. $result = $this->db->query('insert into accounts (a_id_number, a_first_name, a_middle_name, a_last_name, a_age, a_password, a_picture) values (?, ?, ?, ?, ?, ?, ?)', $id_number, $first_name, $middle_name, $last_name, $age, $password, $picture);
  16. $this->loadAccount($this->db->getId());
  17. } else {
  18. $this->loadAccount($result['a_id']);
  19. }
  20. }
  21.  
  22. public function loadAccount($id) {
  23. $this->db_id = $id;
  24.  
  25. $result = $this->db->query("select * from accounts where a_id = ?", array($id))->fetchArray();
  26.  
  27. foreach ($result as $var=>$value) {
  28. $field_name = substr($var, 2, 1000);
  29. $this->{$field_name} = $value;
  30. }
  31. }
  32.  
  33.  
  34. public function __destruct() {
  35. //echo "This object class is being destroyed -- " . __CLASS__ . "\n";
  36. }
  37.  
  38. public function setProperty($field, $value) {
  39. $this->{$field} = $value;
  40.  
  41. $this->db->query("update accounts set a_".$field." = UNHEX('".bin2hex($value)."') where a_id = '".$this->db_id."'");
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement