Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
require_once"DataObject.class.php";
class Member extends DataObject{

protected $data=array(
"id"=>" ",
"firstName"=>"",
"lastName"=>"",
"username"=>"",
"password"=>"",
"joinDate"=>"",
"gender"=>"",
"department"=>"",
"emailAddress"=>"",
"otherInterests"=>""
);

private $_department=array(
"biotech"=>"Biotech",
"computerscience"=>"ComputerScience",
"civil"=>"Civil",
"electrical"=>"Electrical",
"mechanical"=>"Mechanical"
);

public static function getMembers($startRow,$numRows,$order){
$conn=parent::connect();
$sql="SELECT SQL_CALC_FOUND_ROWS *FROM".TBL_MEMBERS."ORDER BY.$order LIMIT:startrow,:numRows";

try{
$st=$conn->prepare($sql);
$st->bindValue(":startRow",$startRow,PDO::PARAM_INT);
$st->bindValue(":numRows",$numRows,PDO::PARAM_INT);
$st->execute();
$membes=array();
foreach($st->fetchAll()as $row){
$members[]=new Member($row);
}
$st=$conn->query("SELECT found_rows() As totalRows");
$row=$st->fetch();
parent::disconnect($conn);
return array($members,$row["totalRows"]);
} catch(PDOException $e){
parent::disconnect($conn);
die("Query failed:".$e->getMessage());
}
}
public static function getByUsername($username){
$conn=parent::connect();
$sql="SELECT * FROM".TBL_MEMBERS."WHERE username=:username";

try{

$st=$conn->prepare($sql);
$st->bindValue(":username",$username,PDO::PARAM_STR);
$st->execute();
$row=$st->fetch();
parent::disconnect($conn);
if($row)return new Member($row);
} catch(PDOException $e){
parent::disconnect($conn);
die("query failed:".$e->getMessage());
}
}

public static function getByEmailAddress($emailAddress){
$conn=parent::connect();
$sql="SELECT * FROM".TBL_MEMBERS."WHERE emailAddress=:emailAddress";

try{
$st=$conn->prepare($sql);
$st->bindValue(":emailAddress",$emailAddress,PDO::PARAM_STR);
$st->execute();
$row=$st->fetch();
parent::disconnect($conn);
if($row)return new Member($row);
} catch(PDOException $e){
parent::disconnect($conn);
die("query failed:".$e->getMessage());
}
}


public function getGenderString(){
return ($this->data["gender"]=="f")?"Female":"Male";
}
public function getDepartmentString(){
return ($this->_department[$this->data["Department"]]);
}
public function getDepartment(){
return $this->_department;
}

public function insert(){
$conn=parent::connect();
$sql="INSERT INTO".TBL_MEMBERS."(
id,
username,
password,
firstname,
lastname,
joinDate,
gender,
department,
emailAddress,
otherInterests
) VALUES(
:id,
:username,
password(:password),
:firstname,
:lastname,
:joinDate,
:gender,
:department,
:emailAddress,
:otheInterests
)";

try{
$st=$conn->prepare($sql);
$st->bindValue(":id",$this->data["id"],POD::PARAM_STR);
$st->bindValue(":username",$this->data["username"],POD::PARAM_STR);
$st->bindValue(":password",$this->data["password"],POD::PARAM_STR);
$st->bindValue(":firstname",$this->data["firstname"],POD::PARAM_STR);
$st->bindValue(":lastname",$this->data["lastname"],POD::PARAM_STR);
$st->bindValue(":joinDate",$this->data["joinDate"],POD::PARAM_STR);
$st->bindValue(":gender",$this->data["gender"],POD::PARAM_STR);
$st->bindValue(":department",$this->data["department"],POD::PARAM_STR);
$st->bindValue(":emailAddress",$this->data["emailAddress"],POD::PARAM_STR);
$st->bindValue(":otheInterests",$this->data["otherInterests"],POD::PARAM_STR);
$st->execute();
parent::disconnect($conn);
}catch(PDOException $e){
parent::disconnect($conn);
die("Query failed:".$e->GetMessage());
}
}
}
?>
Posted
Comments
Sergey Alexandrovich Kryukov 26-May-14 2:01am    
Sorry, this is not a question. Isn't the error message self-describing? Which part of it is unclear to you?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900