<?php
class dBconn{
	 public  $dbcon;
   public  $host="localhost";
   public  $dbname="simuyangu";
   public  $user="root";
   public  $pwd="";


                                      //FUNCTION FOR DATABASE CONNECTION GOES HERE
 
function __construct()

{
         $this->dbcon = new PDO("mysql:dbname=$this->dbname;host=$this->host;",$this->user,$this->pwd);
          
}

function getMyPhone($ownID){
  try{
    $myp=$this->dbcon->prepare("select * from phone where userid=:em");
    $myp->bindParam(":em",$ownID);
    $myp->execute(); 

     return $myp;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
  function login($username,$password){
  try{
    $Rs=$this->dbcon->prepare("select * from users where email=:em and password=:pwd");
    $Rs->bindParam(":em",$username);
    $Rs->bindParam(":pwd",$password);
      $Rs->execute(); 
    if ($Rs->rowCount()>0)
     {
      /////////////
         //$rg=Date("h:i:sa");
    
        $regdate=Date("Y-m-d"); $time=Date("h:i:sa");
         $data=array($time,$regdate,$password,$username);
 
         $Qr=$this->dbcon->prepare("update users set lastlogTime=?, lastLogin =? where password=? and email=?"); 
         $Qr->execute($data);
      
      /////////////////
     }
        return $Rs;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


                                         // CLASS TERMINAL
}
function addClient($fname,$lname,$phoneno,$email,$pwd,$date){
  
 
 $data=array($fname,$lname,$phoneno,$email,$date,$pwd);
   try{
    $Qr=$this->dbcon->prepare("insert into users(fname,lname,phoneno,email,userid) values(?,?,?,?,?)");
    $Qr->execute($data);
    if($Qr->rowCount()>0)
    {
          return $Qr;
    }
    else
    {
      return $Qr;// $Re=$Qr->ErrorInfo();//"Data not saved resubmit the form!..";
    }

    }
    catch(PDOException $ex){
  $ex->getMessage();
    }
   } 
