第三天1+x笔记
一、MySQL数据处理
1.1添加数据
insert into 表名 values(值1,值2,值3)
示例如下:
添加一条数据
insert into stu values ('001','王小二','男','2020','20030');
按列依次添加
insert into stu(sno,sname,class)
1.2 更新语句
update 表名 set 字段='值1',字段2='值2' where 条件
1.3 删除语句
delete from 表名 where 条件
1.4 基本查询
select * from 表名 limit 3
表示查询3条
select * from 表名 limit0,3
表示查询从索引号为0的开始查询,查询3条
1.5 聚合函数
sum:对数值型求和
avg:对数值求平均值
max:求最大值
min:求最小值
count:计数
1.6 去重
select distinct snow from score
1.7 别名
select sno as 学号, sname as 姓名 from student;
1.8分组
select sno,sum (grade) from score group by sno;
1.9分组后加条件
select sno from score group by sno having count (*) >=2;
2.0 降序排列
select * from score order by grade desc;
2.1分页
select * from student limit 3;--索引默认从0开始--
select * from student limit 0,3;
2.2连表查询
select s.id,s.name,c.cid from student as s join classes as c on s.ci=c.cid
二、MySQL高级知识
2.1 视图
视图是虚拟表,是从基本表中派生出来的,可以像基本表一样对其进行操作。
创建视图:
create view 视图名 as select 语句;
删除视图:
drop view 视图名;
2.2 索引
索引是面向数据库本身的,用于查询优化等操作
索引分为:普通索引、唯一索引、组合索引
语法:
--创建普通索引--
create index 索引名 on 表名(列名);
比如: create index test1 on student(name)
--删除索引--
drop index index_name on table_name;
比如:drop index test1 on student
--创建唯一索引--
create unique index 索引名 on 表名;
比如:create unique index test2 on student(name);
--创建普通组合索引--
create index 索引名 on 表名(列名1,列名2,..;)
--查看索引--
show index from 表名 [from <数据库名>];
比如:show index from student
三、PHP基础语言
语言基础
注释
//单行注释
/*多行注释*/
//结束符使用英文分号‘;’
常用命名和系统函数
echo:只能输入字符串、数字、布尔类型的数据
var_dump()此函数显示一个或多个表达式的结构信息,包括表达式的类型与值。
print_r()只能打印出数组的结构,不能显示每个元素的类型信息
require和include
require
常用于引入外部文件,如果引入外部文件失败,汇报Fatal错误,会影响后续代码的执行。
include
常用于引入外部文件,如果引入外部文件失败,汇报warning错误,不会影响后续代码的执行。
require_once
避免重复引入,其他规则则同 require
include_once
避免重复引入,其他规则则同include
变量和常量
变量:$变量名 = 表达式
常量两种定义形式:
defined("常量名,表达式");
const 常量名 = 表达式;
数据类型
四种标量:
布尔型(boolean):true或false。
整形(integer)
浮点型(float)
字符串(string)
两种复合型:array和object
两种特殊类型
资源型(resource):变量可以是文件夹、一个文件、从数据库中得到的结果集等。
空型(null):表示一种状态,变量没有任何值。
数组
第一:数组分类包含关联数组和索引数组
第二:定义数组的多种形式:
$a[] = 10;
$a['name'] = '张三';
$b = array(10,20,30); $b = array('name'=>'张三','sex'=>'男','age'=>28);
或者快捷赋值:
$c = [10,20,30]; $c = ['name'=>'张三','sex'=>'男','age'=>28];
第三:数组的取值
$group = array(
'one'=>array('张三','李四','王五'),
'two'=>array('赵六','孙七'),
);
第四:数组的循环
$arr = [11,22,33,44,55];
for($i=0; $i<count($arr); $i++){
var_dump($arr[$i]);
};
//foreach------------------------------------------------------------
$f_arr=["name" => "zhangsan","age" => 18,"sex" => "m"];
foreach ($f_arr as $key => $value) {
echo $key.":".$value."<br>";
};
//list (只用于索引数组) ------------------------------------------------
list($a,$b,$c,$d,$e) = ["张三","李四","王五","小明","小红"];
echo $a,$b,$c,$d,$e;
运算符
算术运算符 + - * / %
赋值运算符 = += -= *= /= %= .=
比较运算符 > >= < <= != !== == ===
逻辑运算符 && || not and or
字符串运算符 .
三元运算符 ==? :
错误抑制符 @