[php]代码库
<?
// class_user.php
require_once("class_mysqlConn.php");
class UserInfo{
protected $userName; //属性,用户名
protected $userPSW ; //属性,用户密码
protected $userAge ; //属性,用户年龄
protected $userGrade ; //属性,用户级别
protected $userInfo; //存储数据库返回信息的数组变量.
protected $mysqlConn;
public function __construct($name){
$this->mysqlConn = new MysqlConn();
$sql = "select * from e_user where username='$name' "; //查询的sql
$rs = $this->mysqlConn->query($sql);
$this->userInfo = $this->mysqlConn->next();
$this->getInfo(); //调用传递信息的方法.
}
// 获取信息传递给属性的方法
protected function getInfo(){
$this->userName = $this->userInfo["username"];
$this->userPSW = $this->userInfo["userpsw"];
$this->userAge = $this->userInfo["userage"];
$this->userGrade = $this->userInfo["usergrade"];
}
//返回每个属性的public 方法.
public function getUserName(){
return $this->userName;
}
protected function getUserPSW(){
return $this->userPSW;
}
public function getUserAge(){
return $this->userAge;
}
public function getUserGrade(){
return $this->userGrade;
}
}
?>