1.简介
Admin.class.php
<?php
//它的一个对象实例,就表示admin表的一条记录
class Admin
{
private $id; //每个字段为一个成语属性
private $name;
private $password;
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function getPassword()
{
return $this->password;
}
public function setId($id)
{
$this->id = $id;
}
public function setName($name)
{
$this->name = $name;
}
public function setPassword($password)
{
$this->password = $password;
}
}
AdminService.class.php
<?php
require_once 'SqlHelper.class.php';
//该类是一个业务逻辑处理类,主要完成对amdin表的操作
class AdminService
{
//提供一个验证用户是否合法的方法
public function checkAdmin($id,$password)
{
$sql = "select password,name from admin where id=$id;";
//创建一个 SqlHelper 对象
$sqlHelper = new SqlHelper();
$res = $sqlHelper->execute_dql($sql);
if($row = $res->fetch_assoc()){
//比对密码
if($password == $row['password']){
return $row['name'];
}
}
//释放资源
$res->free();
$sqlHelper->close_connect();
return false;
}
}