<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
<?php
class MysqlConn {
private $conn;
private $my_db;
private $result;
public function __construct() {
require_once("db_config.php");
$this->conn = mysql_pconnect($db_server, $db_user, $db_pwd);
$this->my_db = mysql_select_db($db_name,$this->conn);//选择数据库
mysql_query("SET NAMES utf8");
}
public function query($sql){
$this->result = mysql_query($sql, $this->conn); // 执行查询语句
return $this->result;
}
public function next(){
return $row = mysql_fetch_array($this->result);
}
public function close(){
mysql_free_result($this->result);
}
//使用转义字符,保证系统安全.
public function escapeString($str){
return mysql_escape_string($str);
}
}
class UserInfo{
protected $userLogin; //属性,用户名
protected $userPwd ; //属性,用户密码
protected $userSex ; //属性,用户年龄
protected $userClass ; //属性,用户级别
protected $userInfo; //存储数据库返回信息的数组变量.
protected $mysqlConn;
public function __construct($name){
$this->mysqlConn = new MysqlConn();
$sql = "SELECT * FROM `userinfo_t` WHERE `userLogin` LIKE '$name'"; //查询的sql
$rs = $this->mysqlConn->query($sql);
$this->userInfo = $this->mysqlConn->next();
$this->getInfo(); //调用传递信息的方法.
}
// 获取信息传递给属性的方法
protected function getInfo(){
$this->userLogin = $this->userInfo["userLogin"];
$this->userPwd = $this->userInfo["userPwd"];
$this->userSex = $this->userInfo["userSex"];
$this->userClass = $this->userInfo["userClass"];
}
//返回每个属性的public 方法.
public function getUserLogin(){
return $this->userLogin;
}
protected function getUserPwd(){
return $this->userPwd;
}
public function getUserSex(){
return $this->userSex;
}
public function getUserClass(){
return $this->userClass;
}
}
?>
</body>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
<?php
class MysqlConn {
private $conn;
private $my_db;
private $result;
public function __construct() {
require_once("db_config.php");
$this->conn = mysql_pconnect($db_server, $db_user, $db_pwd);
$this->my_db = mysql_select_db($db_name,$this->conn);//选择数据库
mysql_query("SET NAMES utf8");
}
public function query($sql){
$this->result = mysql_query($sql, $this->conn); // 执行查询语句
return $this->result;
}
public function next(){
return $row = mysql_fetch_array($this->result);
}
public function close(){
mysql_free_result($this->result);
}
//使用转义字符,保证系统安全.
public function escapeString($str){
return mysql_escape_string($str);
}
}
class UserInfo{
protected $userLogin; //属性,用户名
protected $userPwd ; //属性,用户密码
protected $userSex ; //属性,用户年龄
protected $userClass ; //属性,用户级别
protected $userInfo; //存储数据库返回信息的数组变量.
protected $mysqlConn;
public function __construct($name){
$this->mysqlConn = new MysqlConn();
$sql = "SELECT * FROM `userinfo_t` WHERE `userLogin` LIKE '$name'"; //查询的sql
$rs = $this->mysqlConn->query($sql);
$this->userInfo = $this->mysqlConn->next();
$this->getInfo(); //调用传递信息的方法.
}
// 获取信息传递给属性的方法
protected function getInfo(){
$this->userLogin = $this->userInfo["userLogin"];
$this->userPwd = $this->userInfo["userPwd"];
$this->userSex = $this->userInfo["userSex"];
$this->userClass = $this->userInfo["userClass"];
}
//返回每个属性的public 方法.
public function getUserLogin(){
return $this->userLogin;
}
protected function getUserPwd(){
return $this->userPwd;
}
public function getUserSex(){
return $this->userSex;
}
public function getUserClass(){
return $this->userClass;
}
}
?>
</body>
</html>
来源 :http://www.nowamagic.net/php/php_CreateClassUser2.php