zoukankan      html  css  js  c++  java
  • mvc模式实现

    listdemo.html负责显示,listModel.class.php负责从数据库存储数据和查找数据,mysql.class.php是操作数据库的类,但不直接使用,model类调用mysql,listmodel类继承model类,将数据库插入指定数据库,list.php将html文件引入,创建listmodel对象,向数据库插入数据,负责显示

    建表语句

    create table list(
    id int not null auto_increment primary key,
    listname varchar(20) not null default '',
    listpsw varchar(20) not null
    )engine myisam charset utf8;
    

     listdemo.html

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>Document</title>
     </head>
     <body>
    <form action='../list.php' method='post'>
    	用户名:<input type='text' name='listname'/><br/>
    	密码:<input type='password' name='listpsw'/><br/>
    	<input type='submit' value='提交'/>
    </from>
     </body>
    </html>
    

     listmodel.class.php

    <?php
    class Model{
        protected $table=null;//是model所控制的表
        protected $db=null;//是引入的类
    
        public function __construct(){
            $this->db=mysql::getIns();
        }
        public function table($table){
            $this->table=$table;
        }
    }
    ?>
    

     list.php

    <?php
    define('ACC',true);
    include('./include/init.php');
    
    
    $data=$_POST;
    
    $list=new listModel();
    print_r($data);
    $res=$list->reg($data);
    if($res){
    	echo '添加成功';
    }else{
    	echo '添加失败';
    }
    ?>
    
  • 相关阅读:
    Linux 中国镜像
    VMWare 安装 Debian 9
    Linux 安装Docker compose 快速方法
    Nginx on Docker 配置
    Docker 中配置Nginx
    Nginx IPV4 问题
    VMWare中CentOS 7 配置 XShell连接
    在CentOS 7 中安装Docker
    Docker for Windows 和虚拟机VMWare共存方案
    Nginx 配置多个站点
  • 原文地址:https://www.cnblogs.com/lzzhuany/p/4769630.html
Copyright © 2011-2022 走看看