Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User{
- public function User($id){
- $this->db=new Db();
- $this->db->query("Select * from User where userID = '".$id . "';" );
- if($this->result=$this->db->nextRow()){
- $this->userID=$this->result['userID'];
- $this->firstName=$this->result['firstName'];
- $this->lastName=$this->result['lastName'];
- $this->email=$this->result['email'];
- $this->address=$this->result['address'];
- $this->userName=$this->result['userName'];
- $this->password=$this->result['password'];
- $this->dateOfBirth=$this->result['dateOfBirth'];
- $this->phone=$this->result['phone'];
- $this->role=$this->result['Role_idRole'];
- $this->city=$this->result['city'];
- $this->province=$this->result['province'];
- $this->postalCode=$this->result['postal_code'];
- }else{
- $this->role=2;//DEFAULT ROLE IS STUDENT
- }
- }
- public function commit(){
- $this->db->commit("
- UPDATE user
- SET
- firstName='".$this->getFirstName(). "',
- lastName='".$this->getLastName()."',
- email='".$this->getEmail()."',
- address='".$this->getAddress()."',
- userName='".$this->getUserName()."',
- password='".$this->getPassword()."',
- dateOfBirth='".$this->getDateOfBirth()."',
- phone='".$this->getPhone()."',
- city='".$this->getCity()."',
- province='".$this->getProvince()."',
- postalCode='".$this->getPostalCode()."'
- WHERE userID=".$this->getUserID().";"
- );
- }
- }//end class user
- class Db{
- //hold the result set
- private $result;
- //holds the sql connection
- private $conn;
- // method declaration
- public function Db(){
- $this->conn= mysql_connect('localhost', 'root', '');
- if (!$this->conn){
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db("mydb", $this->conn);
- }
- /**
- * Executes the query and stores the result in $result
- * Enter description here ...
- * @param unknown_type $query
- */
- public function query($query){
- $this->result=mysql_query($query);
- }
- public function commit($query){
- mysql_query($query);
- }
- /**
- * Return the next row
- * Enter description here ...
- */
- public function nextRow(){
- return mysql_fetch_array($this->result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement