Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1.  
  2.     <?php
  3.     class MySQLDao {
  4.     var $dbhost = null;
  5.     var $dbuser = null;
  6.     var $dbpass = null;
  7.     var   $conn = null;
  8.     var $dbname = null;
  9.     var $result = null;
  10.    
  11.     function __construct() {
  12.     $this->dbhost = Conn::$dbhost;
  13.     $this->dbuser = Conn::$dbuser;
  14.     $this->dbpass = Conn::$dbpass;
  15.     $this->dbname = Conn::$dbname;
  16.     }
  17.    
  18.     public function openConnection() {
  19.     $this->conn = new mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
  20.     if (mysqli_connect_errno())
  21.     echo new Exception("Could not establish connection with database");
  22.     }
  23.    
  24.     public function getConnection() {
  25.     return $this->conn;
  26.     }
  27.    
  28.     public function closeConnection() {
  29.     if ($this->conn != null)
  30.     $this->conn->close();
  31.     }
  32.    
  33.     public function getUserDetails($email)
  34.     {
  35.     $returnValue = array();
  36.     $sql = "select * from user where email='" . $email . "'";
  37.    
  38.     $result = $this->conn->query($sql);
  39.     if ($result != null && (mysqli_num_rows($result) >= 1)) {
  40.     $row = $result->fetch_array(MYSQLI_ASSOC);
  41.     if (!empty($row)) {
  42.     $returnValue = $row;
  43.     }
  44.     }
  45.     return $returnValue;
  46.     }
  47.    
  48.     public function getUserDetailsWithPassword($email, $userPassword)
  49.     {
  50.     $returnValue = array();
  51.     $sql = "select id, email from user where email='" . $email . "' and password='" .$userPassword . "'";
  52.    
  53.     $result = $this->conn->query($sql);
  54.     if ($result != null && (mysqli_num_rows($result) >= 1)) {
  55.     $row = $result->fetch_array(MYSQLI_ASSOC);
  56.     if (!empty($row)) {
  57.     $returnValue = $row;
  58.     }
  59.     }
  60.     return $returnValue;
  61.     }
  62.    
  63.     public function registerUser($email, $password)
  64.     {
  65.     $sql = "insert into user set email=?, user_password=?";
  66.     $statement = $this->conn->prepare($sql);
  67.    
  68.         if (!$statement)
  69.     throw new Exception($statement->error);
  70.    
  71.    
  72.     $statement->bind_param("ss", $email, $password);
  73.     $returnValue = $statement->execute();
  74.    
  75.     return $returnValue;
  76.     }
  77.     }
  78.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement