文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>php 面向对象学习中的一个例子

php 面向对象学习中的一个例子

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


?php
    class UserInfo
    {
        public $userName;
        public $password;
        public $age;
        public $tel;
        public $userInfo = array();
        
        function __construct($username)
        {
            require("config.php");
            $sql = "SELECT * FROM admin WHERE username='$username'";
            $db_link = new mysqli($server, $user, $password, $database);
            if(mysqli_connect_error())
            {
                echo "connect to database error!";
                exit;
            }
            if($result = $db_link->query($sql))
            {
                $this->userInfo = $result->fetch_assoc();
            }
            $this->getInfo();
        }
        function getInfo()
        {
            $this->userName     =     $this->userInfo['username'];
            $this->password     =      $this->userInfo['password'];
            $this->age            =     $this->userInfo['age'];
            $this->tel            =     $this->userInfo['tel'];
        }
        function getUserName()
        {
            return $this->userName;
        }
        function getPassword()
        {
            return $this->password;
        }
        function getAge()
        {
            return $this->age;
        }
        function getTel()
        {
            return $this->tel;
        }
    }
    $user = new UserInfo('名字');
    echo $user->getUserName();
   
?>


上边的代码有错误,不能执行,明天再查原因。。。。。。接宝贝去.


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

哥布林弹球b服手游下载

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

小马样式盒游戏下载

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

异变小镇中文版下载安装

冒险解谜 下载