[PHP] PHP实体类 →→→→→进入此内容的聊天室

来自 , 2021-03-30, 写在 PHP, 查看 160 次.
URL http://www.code666.cn/view/8a56257e
  1. <?
  2. // class_user.php
  3. require_once("class_mysqlConn.php");
  4. class UserInfo{
  5.         protected $userName;  //属性,用户名
  6.         protected $userPSW ;  //属性,用户密码
  7.         protected $userAge ;  //属性,用户年龄
  8.         protected $userGrade ; //属性,用户级别
  9.         protected $userInfo; //存储数据库返回信息的数组变量.
  10.         protected $mysqlConn;
  11.         public function __construct($name){
  12.                 $this->mysqlConn = new MysqlConn();
  13.                 $sql = "select * from e_user where username='$name' "; //查询的sql
  14.                 $rs = $this->mysqlConn->query($sql);
  15.                 $this->userInfo = $this->mysqlConn->next();
  16.                 $this->getInfo(); //调用传递信息的方法.
  17.         }
  18.         // 获取信息传递给属性的方法
  19.         protected function getInfo(){
  20.                 $this->userName = $this->userInfo["username"];
  21.                 $this->userPSW = $this->userInfo["userpsw"];
  22.                 $this->userAge = $this->userInfo["userage"];
  23.                 $this->userGrade = $this->userInfo["usergrade"];
  24.         }
  25.        
  26.         //返回每个属性的public 方法.
  27.         public function getUserName(){
  28.                 return $this->userName;
  29.         }
  30.        
  31.         protected function getUserPSW(){
  32.                 return $this->userPSW;
  33.         }
  34.        
  35.         public function getUserAge(){
  36.                 return $this->userAge;                         
  37.         }
  38.        
  39.         public function getUserGrade(){
  40.                 return $this->userGrade;
  41.         }
  42. }
  43. ?>
  44.  

回复 "PHP实体类"

这儿你可以回复上面这条便签

captcha