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进入数据库时会出错...
相关阅读 更多 +
排行榜 更多 +