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();
?>
上边的代码有错误,不能执行,明天再查原因。。。。。。接宝贝去.
相关阅读 更多 +
排行榜 更多 +