Advertisement
dracula1337

Untitled

Aug 7th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <?php
  2.  
  3. class access {
  4.  
  5. var $host = null;
  6. var $user = null;
  7. var $pass = null;
  8. var $name = null;
  9. var $conn = null;
  10. var $result = null;
  11.  
  12.  
  13. function construct($dbhost , $dbuser , $dbpass , $dbname){
  14.  
  15.  
  16. $this->host = $dbhost;
  17. $this->user = $dbuser;
  18. $this->pass = $dbpass;
  19. $this->name = $dbname;
  20.  
  21. }
  22. public function connect() {
  23.  
  24. $this->conn = new mysqli($this->host , $this->user , $this-> pass , $this->name);
  25.  
  26. if(mysqli_connect_error()){
  27. echo 'could not connect database';
  28.  
  29. }else{
  30. echo 'Connected and select';
  31. }
  32.  
  33. $this->conn->set_charset("utf8");
  34. }
  35.  
  36. public function disconnect(){
  37. if($this->conn != null){
  38.  
  39. $this->conn->close();
  40.  
  41. }
  42.  
  43. }
  44.  
  45. public function registerUser($email , $password , $salt , $fullname , $phone) {
  46.  
  47. $sql = "INSERT INTO `users` SET `email`=?, `password`=? ,`salt`=?, `fullname`=?, `phone`=?";
  48. $statement = $this->conn->prepare($sql);
  49.  
  50.  
  51. if(!$statement){
  52.  
  53.  
  54.  
  55.  
  56. //throw new Exception($statement->error);
  57. try{
  58. throw new Exception("error");
  59. } catch (Exception $e){
  60. echo $e->getMessage();
  61.  
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. }
  71.  
  72. $statement->bind_param('sssss', $email, $password, $salt, $fullname, $phone);
  73.  
  74. $returnValue = $statement->execute();
  75. return $returnValue;
  76.  
  77.  
  78.  
  79.  
  80.  
  81. }
  82.  
  83.  
  84.  
  85. public function selectUser($email){
  86.  
  87.  
  88. $sql = "SELECT * FROM users WHERE email='".$email."'";
  89. $result = $this->conn->query($sql);
  90.  
  91. if($result != null && (mysqli_num_rows($result) >= 1)){
  92.  
  93.  
  94.  
  95. $row = $result->fetch_array(MYSQLI_ASSOC);
  96.  
  97. if(!empty($row)){
  98. $returnArray = $row;
  99. }
  100.  
  101.  
  102.  
  103.  
  104. }
  105.  
  106.  
  107. return $returnArray ;
  108.  
  109. }
  110.  
  111.  
  112. }
  113.  
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement