php典型三层架构
来源:互联网 发布:家居安装网络报价 编辑:程序博客网 时间:2024/06/05 06:53
php典型三层架构
数据库
CREATE TABLE `t_user` (
`u_id` int(11) NOT NULL,
`u_name` varchar(20) default NULL,
`u_password` varchar(20) default NULL,
PRIMARY KEY (`u_id`)
)
page文件夹(表现层)
userslist.php
<?php
include_once '../facade/usersAction.php';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户管理</title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><a href="usersadd.php">添加用户</a></td>
</tr>
<tr>
<td>
<form action="userslist.php" method="post" id="Find">
用户名:
<input type="text" name="userName" id="userName" value="<?php echo $userName?>">
<input type="submit" value="搜索"></form>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20%">用户id</td>
<td width="20%">用户名</td>
<td width="20%">用户密码</td>
</tr>
<?php
for($i = 0; $i < sizeof ( $userlist ); $i ++)
{
echo '<tr><td width="20%">' . $userlist[$i][0] . '</td><td>'.$userlist[$i][1].'</td><td>'.$userlist[$i][2].'<td/></tr>';
}
?>
</table>
</body>
</html>
facade文件夹(业务层)
usersAction.php
<?php
include_once '../DAL/usersDal.php';
if(isset($_POST["userName"])&&!$_POST["userName"]=='')
{
$userlist = findUsers($_POST["userName"]);
$userName = $_POST["userName"];
}
else
{
$userlist = findUsers('');
$userName = '';
}
?>
DAL文件夹(数据层)
usersDal.php
<?php
function findUsers($usersName)
{
//包含配置文件
include_once '../config.php';
//创建数据库连接
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database);
//执行查询
$query="select * from t_user ";
if(isset($usersName)&&!$usersName=='')
{
$query = $query."where u_name = '".$usersName."'";
}
$result=mysql_query($query,$conn);
//将返回值放入数组
$array = array();
while($row=mysql_fetch_row($result))
{
$array[] = $row;
}
//释放资源,关闭连接
mysql_free_result($result);
mysql_close();
//返回结果
return $array;
}
?>
<?php
$mysql_server_name="localhost:3306"; //数据库服务器名称
$mysql_username="root"; // 连接数据库用户名
$mysql_password="root"; // 连接数据库密码
$mysql_database="network"; // 数据库的名字
?>
- php典型三层架构
- PHP三层架构
- 一个典型的C/S架构的三层架构设计图
- 天轰穿典型三层架构留言本9级视频教程
- 谈谈JavaEE的mvc模式及典型的三层架构
- ASP.NET典型三层架构企业级医药行业ERP系统实战
- php架构学习-传统三层架构
- 典型的三层结构
- 【三层】三层架构初识
- 三层架构
- 三层架构
- 三层架构
- 三层架构
- 三层架构
- 三层架构
- 三层架构
- 三层架构
- 三层架构
- 开源项目汇总
- 黑马程序员----其他对象
- 文件上传到服务器某个文件夹
- 学习操作系统开发的网站资源(随时补充)
- 常用连续型分布介绍及R语言实现
- php典型三层架构
- Matlab求三个数的互质的整数比(最简比)
- csv导入mysql
- android的PowerManager和PowerManager.WakeLock
- Lodop打印控件打印
- 蛇形填数
- Android事件传递机制
- Sublime text2 常用插件
- 关于跨浏览器的部分代码的封装