圖片上傳





在控制器里還要引用一個model文件和yii的組件 use app\models\UploadForm;? use yii\web\UploadedFile;
圖片預(yù)覽

索引
1> 普通索引(index)(MUL代表普通索引)
? 特點:沒有任何限制,當(dāng)我們定義了普通索引之后,直接搜索數(shù)據(jù)即可使用它
? (1) 在創(chuàng)建表的時候,定義一個普通索引
????? 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代表唯一索引)
?特點:具有唯一索引的字段,它的值只能出現(xiàn)一次,出現(xiàn)重復(fù)的值則會報錯!
? 同時,一個表中可以有多個字段添加唯一索引
(1)在建表時創(chuàng)建唯一索引的方法一
???? 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)在建表時創(chuàng)建唯一索引的方法二
????? 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)
?? 特點:它的唯一索引基本上使用方法以及特性一致,唯一的區(qū)別是,唯一索引在
一個表中可以多次定義、主鍵索引只能定義一次,而且主鍵索引一般會添加到id字段當(dāng)中
(1)建表時創(chuàng)建一個主鍵索引的方法
?? 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) 刪除主鍵索引的方法
? 因為主鍵索引比較特殊,所以我們在刪除主鍵索引時,必須先來查看表結(jié)構(gòu),看表中
? 具有主鍵索引的那個字段,是否同時擁有 auto_increment 這個約束條件,如果有,
? 先刪除 auto_increment 這個約束條件,之后才能刪除主鍵索引
1.先查看表結(jié)構(gòu),查看是否擁有 auto_increment 關(guān)鍵字
? desc 表名;
2.如果有 auto_increment 關(guān)鍵字,則需要先刪除該關(guān)鍵字
? alter table test1 modify id int unsigned not null;
? alter table 表名 modify 字段名 字段類型 約束條件;
3.刪除主鍵索引
? alter table test1 drop primary key;
? alter table 表名 drop 主鍵索引;