900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > php mysql curd_Php mysql 常用代码 CURD操作以及简单查询

php mysql curd_Php mysql 常用代码 CURD操作以及简单查询

时间:2022-10-06 19:50:07

相关推荐

php mysql curd_Php     mysql 常用代码 CURD操作以及简单查询

C/S:Client Server

B/S:Brower Server

php主要实现B/S

LAMP :Linux系统 A阿帕奇服务器 Mysql数据库 Php语言

mysql常用代码

创建表

1 create tableCeShi12 (3 Uid varchar(50) primary key,4 Pwd varchar(50),5 Name varchar(50),6 Nation varchar(50),7 foreign key(Nation) referencesNation(Code)8 )

关系型数据库:表和表之间是有关系存在的

创建表的几个关键字:

1、主键:primary key

2、非空:not null

3、自增长列:auto_increment

4、外键关系:foreign key(列名) references 表名(列名)

CRUD操作:

1、添加数据:

insert into Info values(‘‘,‘‘,‘‘,‘‘,‘‘)//要求values括号里面的值得个数要和表里面列数相同

insert into Info (Code,Name) values(‘‘,‘‘) 添加指定列的值

2、修改数据

update Info set Name=‘张三‘ where Code =‘p001‘

3、删除数据

delete from Info where Code=‘p001‘

写查询语句需要注意:

1、创建表的时候,最后一列后面不要写逗号。

2、如果有多条语句一起执行,注意在语句之前加分号分隔

3、写代码所有的符号都是半角额(英文状态下)

1、普通查询,差所有

select * from Info #差所有数据

select Code,Name from Info #查指定列

2、条件查询:

select * from Info where Code=‘p001‘ #一个条件

select * from Info where Name=‘张三‘ and Nation =‘p001‘ #两个条件并列的关系

select * from Info where Name=‘张三‘ or Nation =‘p001‘ #两个条件或的关系

3、排序查询

select * from Info order bu birthday # 默认升序排列asc 如果降序排列desc

select * from Car order by Brand,Oil desc # 多列排序

4、聚合函数

select count (*) from Info #取个数

select sum(Price) from Car #查询Price列的和

select avg(Price) from Car #查询price列的平均值

select max(Price) from Car #查询price列的最大值

select min(Price) from Car #查询price列的最小值

5、分页查询

select * from Car limit 0,5 #跳过n条数据取m条数据

6、分组查询

select brand from group by brand #简单分组查询

select brand from group by brand having count(*)>2 #查询系列里面车的数量大于2的系列

7、去重查询

select distinct brand from car

8、修改列名

select brand as ‘系列‘ from car

9、模糊查询

select * from car where Name like ‘_迪%‘ %代表任意多个字符 _代表一个字符

10、离散查询

select * from car where code in(‘c001‘,‘c002‘,‘c003‘,‘c004‘)

select * from car where code not in(‘c001‘,‘c002‘,‘c003‘,‘c004‘)

原文:/zk0533/p/5405838.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。