Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. class User{
  2. public function User($id){
  3. $this->db=new Db();
  4. $this->db->query("Select * from User where userID = '".$id . "';" );
  5. if($this->result=$this->db->nextRow()){
  6. $this->userID=$this->result['userID'];
  7. $this->firstName=$this->result['firstName'];
  8. $this->lastName=$this->result['lastName'];
  9. $this->email=$this->result['email'];
  10. $this->address=$this->result['address'];
  11. $this->userName=$this->result['userName'];
  12. $this->password=$this->result['password'];
  13. $this->dateOfBirth=$this->result['dateOfBirth'];
  14. $this->phone=$this->result['phone'];
  15. $this->role=$this->result['Role_idRole'];
  16. $this->city=$this->result['city'];
  17. $this->province=$this->result['province'];
  18. $this->postalCode=$this->result['postal_code'];
  19. }else{
  20. $this->role=2;//DEFAULT ROLE IS STUDENT
  21. }
  22. }
  23. public function commit(){
  24. $this->db->commit("
  25. UPDATE user
  26. SET
  27. firstName='".$this->getFirstName(). "',
  28. lastName='".$this->getLastName()."',
  29. email='".$this->getEmail()."',
  30. address='".$this->getAddress()."',
  31. userName='".$this->getUserName()."',
  32. password='".$this->getPassword()."',
  33. dateOfBirth='".$this->getDateOfBirth()."',
  34. phone='".$this->getPhone()."',
  35. city='".$this->getCity()."',
  36. province='".$this->getProvince()."',
  37. postalCode='".$this->getPostalCode()."'
  38. WHERE userID=".$this->getUserID().";"
  39.  
  40. );
  41.  
  42. }
  43. }//end class user
  44.  
  45. class Db{
  46. //hold the result set
  47. private $result;
  48. //holds the sql connection
  49. private $conn;
  50. // method declaration
  51. public function Db(){
  52. $this->conn= mysql_connect('localhost', 'root', '');
  53. if (!$this->conn){
  54. die('Could not connect: ' . mysql_error());
  55. }
  56. mysql_select_db("mydb", $this->conn);
  57. }
  58. /**
  59. * Executes the query and stores the result in $result
  60. * Enter description here ...
  61. * @param unknown_type $query
  62. */
  63. public function query($query){
  64. $this->result=mysql_query($query);
  65. }
  66. public function commit($query){
  67.  
  68. mysql_query($query);
  69. }
  70. /**
  71. * Return the next row
  72. * Enter description here ...
  73. */
  74. public function nextRow(){
  75. return mysql_fetch_array($this->result);
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement