Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1.         public function login($userName, $password){
  2.             $this->connection = Database::getInstance()->OpenConnection();
  3.             $sql = "select * from user where user_name = ? and password = ?;";
  4.            
  5.             $statement = mysqli_prepare($this->connection, $sql);
  6.            
  7.             //if any error happen in connection
  8.             if (!$statement) {
  9.                 echo 'erro na consulta: '. $this->connection->errno .' - '. $this->connection->error;
  10.             }
  11.            
  12.             //associate the user name and password with sql parameters,
  13.             //execute the query and store the result
  14.             $statement->bind_param('ss', $userName,$password);
  15.             $statement->execute();
  16.             $result = $statement->get_result();
  17.                
  18.             $user;
  19.            
  20.             //create and set the user variable
  21.             while($row = mysqli_fetch_array($result)){
  22.                 $user = new User($row["idUser"], $row["name"], $row["email"], $row["user_name"], $row["password"], $row["type"], $row["active"], $row["idAdministrator"]);
  23.             }
  24.            
  25.             echo "teste: ".$user->name;
  26.    
  27.             //close statement and connection
  28.             $statement->close();
  29.             Database::getInstance()->CloseConnection($this->connection);
  30.            
  31.             return $user;
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement