Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DataManagerDao
- {
- var $dbhost = null;
- var $dbuser = null;
- var $dbpassword = null;
- var $dbname = null;
- var $connection = null;
- var $result = null;
- function __construct(){
- $this->dbhost = Connection::__getDBHost();
- $this->dbuser = Connection::__getDBUser();
- $this->dbpassword = Connection::__getDBPassword();
- $this->dbname = Connection::__getDBName();
- }
- public function openDBConnection(){
- try{
- $this->connection = new mysqli($this->dbhost, $this->dbuser, $this->dbpassword, $this->dbname);
- }catch (Exception $ex){
- die("Non รจ possibile connettersi al database " . $ex->getMessage());
- }
- }
- // funzione per la connessione al database mysql
- public function db_connection(){
- $this->connection = new mysqli($this->dbhost, $this->dbuser, $this->dbpassword, $this->dbname);
- if (mysqli_connect_error()) {
- return false;
- }
- mysqli_set_charset($this->connection, 'utf8');
- return true;
- }
- function isDBConnected(){
- if ($this->connection != null)
- return true;
- return false;
- }
- // restituisce la connessione
- public function getConnection(){
- return $this->connection;
- }
- public function closeDBConnection(){
- if (!empty($this->connection)) {
- $this->connection->close();
- }
- }
- public function getUserDetails($email){
- $returnValue = array();
- $sql = "SELECT * FROM account_user WHERE Email = '" . $email . "'";
- $result = $this->connection->query($sql);
- if ($result != null && (mysqli_num_rows($result) >= 1)){
- $row = $result->fetch_array(MYSQLI_ASSOC);
- if (!empty($row)){
- $returnValue = $row;
- }
- }
- return $returnValue;
- }
- public function getUserDetailsWithPassword($email, $password){
- $returnValue = array();
- $sql = "SELECT User_ID, Email FROM account_user WHERE Email = '" . $email . "' AND Password = '" . $password . "'";
- $result = $this->connection->query($sql);
- if ($result != null && (mysqli_num_rows($result) >= 1)){
- $row = $result->fetch_array(MYSQLI_ASSOC);
- if (!empty($row)){
- $returnValue = $row;
- }
- }
- return $returnValue;
- }
- public function registerUser($username, $email, $password){
- $sql = "INSERT INTO account_user SET Username=?, Email=?, Password=?";
- $stmt = $this->connection->prepare($sql);
- if (!$stmt){
- throw new Exception($stmt->error);
- }
- $stmt->bind_param("sss", $username, $email, $password);
- $returnValue = $stmt->execute();
- return $returnValue;
- }
- public function storeEmailToken($user_id, $emailToken){
- $sql = "INSERT INTO email_tokens SET User_ID=?, email_token=?";
- $stmt = $this->connection->prepare($sql);
- if (!$stmt){
- throw new Exception($stmt->error);
- }
- $stmt->bind_param("is", $user_id, $emailToken);
- $returnValue = $stmt->execute();
- return $returnValue;
- }
- public function getUserWithToken($emailToken){
- $returnValue = array();
- $sql = "SELECT User_ID, email_token FROM email_tokens WHERE email_token='" . $emailToken ."'";
- $result = $this->connection->query($sql);
- if ($result != null && (mysqli_num_rows($result) >= 1)){
- $row = $result->fetch_array(MYSQLI_ASSOC);
- if (!empty($row)){
- $returnValue = $row['User_ID'];
- }
- }
- return $returnValue;
- }
- public function setEmailConfirmedStatus($status, $user_id){
- $sql = "UPDATE account_user SET isEmailConfirmed=? WHERE User_ID=?";
- $stmt = $this->connection->prepare($sql);
- if (!$stmt)
- throw new Exception($stmt->error);
- $stmt->bind_param("ii", $status, $user_id);
- $returnValue = $stmt->execute();
- return $returnValue;
- }
- public function deleteUsedToken($emailToken){
- $sql = "DELETE FROM email_tokens WHERE email_token=?";
- $stmt = $this->connection->prepare($sql);
- if (!$stmt)
- throw new Exception($stmt->error);
- $stmt->bind_param("s", $emailToken);
- $returnValue = $stmt->execute();
- return $returnValue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement