文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>php oo 学习

php oo 学习

时间:2007-01-15  来源:liuxingyuyuni



config.php
?php
    $server = "localhost";
    $user     = "root";
    $pass     = "wowangle";
    $db     = "test";
?>

oo.php

?php
    class UserInfo
    {
        private     $name;
        private     $pass;
        private     $age;
        private     $tel;
        private     $userInfo;
        
        public function __construct($username)
        {
            require("config.php");
            $conn = new mysqli($server, $user, $pass, $db);
            $conn->query('set names gb2312');
            $res = $conn->query("SELECT * FROM test where name='$username'");
            $this->userInfo = $res->fetch_assoc();
            $conn->close();
            $this->getUserInfo();
        }
        public function getUserInfo()
        {
            $this->name         = $this->userInfo['name'];
            $this->pass        =    $this->userInfo['pass'];
            $this->age        =    $this->userInfo['age'];
            $this->tel        =    $this->userInfo['tel'];
        }
        public function getUserName()
        {
            return $this->name;
        }
        
        public function getUserPass()
        {
            return $this->pass;
        }
        
        public function getUserAge()
        {
            return $this->age;
        }
        public function getUserTel()
        {
            return $this->tel;
        }
    }
    $user = new UserInfo('小破孩');
    echo $user->getUserName();
    echo $user->getUserTel();
   
?>

*注意编码,否则SQL进入数据库时会出错...


相关阅读 更多 +
排行榜 更多 +
哥布林弹球b服手游下载

哥布林弹球b服手游下载

休闲益智 下载
小马样式盒游戏下载

小马样式盒游戏下载

休闲益智 下载
异变小镇中文版下载安装

异变小镇中文版下载安装

冒险解谜 下载