图片上传||预览

图片上传

表单


第一钟ajax
第二种ajax


第一中ajax的控制器
第二种ajax的控制器

在控制器里还要引用一个model文件和yii的组件 use app\models\UploadForm;  use yii\web\UploadedFile;

图片预览


ajax预览代码

索引

1> 普通索引(index)(MUL代表普通索引)

  特点:没有任何限制,当我们定义了普通索引之后,直接搜索数据即可使用它

  (1) 在创建表的时候,定义一个普通索引

      create tabel test1(

        id int unsigned not null,

       name varchar(32) not null,

      sex enum('m','w') not null default 'w',

      age tinyint not null default 18,

     index id(id) 索引类型 索引名(字段名)

  );

(2)在建表之后,给某个字段添加普通索引

   create index id on test1(id);

   create 索引类型 索引名 on 表名(字段名);

(3)删除一个普通索引的方法

  drop index id on test1;

  drop 索引类型 索引名 on 表名;

2> 唯一索引(unique)(UNI代表唯一索引)

 特点:具有唯一索引的字段,它的值只能出现一次,出现重复的值则会报错!

  同时,一个表中可以有多个字段添加唯一索引

(1)在建表时创建唯一索引的方法一

     create table test1(

      id int unsigned not null,

     name varchar(32) not null,

    sex enum('w','m') not null default 'm',

    age tinyint not null default 18,

    unique index name(name) //索引类型 索引名(字段名)

   );

(2)在建表时创建唯一索引的方法二

      create table test1(

       id int unsigned not null,

      name varchar(32) not null unique, //直接给字段添加唯一索引

      sex enum('w','m') not null default 'w',

     age tinyint not null default 18

  );

(3) 在建表之后添加一个唯一索引

  create unique index id on test1(id);

  create 索引类型 索引名 on 表名(字段名);

(4)删除一个表中的唯一索引的方法

drop index id on test1;

drop 索引类型 索引名 on 表名;

3> 主键索引(primary key)

   特点:它的唯一索引基本上使用方法以及特性一致,唯一的区别是,唯一索引在

一个表中可以多次定义、主键索引只能定义一次,而且主键索引一般会添加到id字段当中

(1)建表时创建一个主键索引的方法

   create table test1(

   id int unsigned not null auto_increment primary key, //添加主键

   name varchar(32) not null,

   sex enum('w','m') not null default 'm',

   age tinyint not null default 18

  );

(2)建表之后,添加一个主键索引的方法

1.alter table test1 change id id int unsigned not null auto_increment primary key;

alter table 表名  change 字段原名 字段新名 类型 约束条件……;

2.alter table test1 modify id int unsigned not null auto_increment priamry key;

   alter table 表名  modify 字段名 类型 约束条件……;

(3) 删除主键索引的方法

  因为主键索引比较特殊,所以我们在删除主键索引时,必须先来查看表结构,看表中

  具有主键索引的那个字段,是否同时拥有 auto_increment 这个约束条件,如果有,

  先删除 auto_increment 这个约束条件,之后才能删除主键索引

1.先查看表结构,查看是否拥有 auto_increment 关键字

  desc 表名;

2.如果有 auto_increment 关键字,则需要先删除该关键字

  alter table test1 modify id int unsigned not null;

  alter table 表名 modify 字段名 字段类型 约束条件;

3.删除主键索引

  alter table test1 drop primary key;

  alter table 表名 drop 主键索引;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • MySQL5.6从零开始学 第一章 初始mysql 1.1数据库基础 数据库是由一批数据构成的有序的集合,这些数据...
    星期四晚八点阅读 1,187评论 0 4
  • MySQL 数据库常用命令 1、MySQL常用命令 create database name; 创建数据库 use...
    55lover阅读 4,833评论 1 57
  • 系统用户: 1.sys system(sys权限最高) 2.sysman(操作企业管理器) 密码是安装的时候输入的...
    3hours阅读 1,616评论 0 0
  • 1.感恩罗老师今天的增员分享,对我一直懒惰和拖延有很大的震撼。 2.感恩二东邀请参加投资班学习,接触下高端人群的生...
    Hello滑先生阅读 146评论 0 0
  • 很久以前,一个山东的手艺人,他很喜欢雕塑妖魔鬼怪的东西,也雕塑得活灵活现,技艺传出去后,很多人都找他雕塑,因此发了...
    老抓阅读 955评论 7 12