文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
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进入数据库时会出错...


相关阅读 更多 +
排行榜 更多 +
边境警察巡逻模拟中文版下载

边境警察巡逻模拟中文版下载

角色扮演 下载
数码宝贝世界复原手机版下载

数码宝贝世界复原手机版下载

角色扮演 下载
土地抢夺者中文手机版下载

土地抢夺者中文手机版下载

策略塔防 下载