PHP常用的会员类与mysql连接类

<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>

</html>


来源 :http://www.nowamagic.net/php/php_CreateClassUser2.php

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值