php mysql curd_Php mysql 常用代码、CURD操作以及简单查询
C/S:Client Server
B/S:Brower Server
php主要實(shí)現(xiàn)B/S
LAMP :Linux系統(tǒng) ? ?A阿帕奇服務(wù)器 ? ?Mysql數(shù)據(jù)庫 ? Php語言
mysql常用代碼
創(chuàng)建表
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 )
關(guān)系型數(shù)據(jù)庫:表和表之間是有關(guān)系存在的
創(chuàng)建表的幾個(gè)關(guān)鍵字:
1、主鍵:primary key
2、非空:not null
3、自增長(zhǎng)列:auto_increment
4、外鍵關(guān)系:foreign key(列名) references 表名(列名)
CRUD操作:
1、添加數(shù)據(jù):
insert into Info values(‘‘,‘‘,‘‘,‘‘,‘‘)//要求values括號(hào)里面的值得個(gè)數(shù)要和表里面列數(shù)相同
insert into Info (Code,Name) values(‘‘,‘‘) 添加指定列的值
2、修改數(shù)據(jù)
update Info set Name=‘張三‘ where Code =‘p001‘
3、刪除數(shù)據(jù)
delete from Info where Code=‘p001‘
寫查詢語句需要注意:
1、創(chuàng)建表的時(shí)候,最后一列后面不要寫逗號(hào)。
2、如果有多條語句一起執(zhí)行,注意在語句之前加分號(hào)分隔
3、寫代碼所有的符號(hào)都是半角額(英文狀態(tài)下)
1、普通查詢,差所有
select * from Info #差所有數(shù)據(jù)
select Code,Name from Info #查指定列
2、條件查詢:
select * from Info where Code=‘p001‘ #一個(gè)條件
select * from Info where Name=‘張三‘ and Nation =‘p001‘ #兩個(gè)條件并列的關(guān)系
select * from Info where Name=‘張三‘ or Nation =‘p001‘ #兩個(gè)條件或的關(guān)系
3、排序查詢
select * from Info order bu birthday # 默認(rèn)升序排列asc 如果降序排列desc
select * from Car order by Brand,Oil desc # 多列排序
4、聚合函數(shù)
select count (*) from Info #取個(gè)數(shù)
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條數(shù)據(jù)取m條數(shù)據(jù)
6、分組查詢
select brand from group by brand #簡(jiǎn)單分組查詢
select brand from group by brand having count(*)>2 #查詢系列里面車的數(shù)量大于2的系列
7、去重查詢
select distinct brand from car
8、修改列名
select brand as ‘系列‘ from car
9、模糊查詢
select * from car where Name like ‘_迪%‘ %代表任意多個(gè)字符 _代表一個(gè)字符
10、離散查詢
select * from car where code in(‘c001‘,‘c002‘,‘c003‘,‘c004‘)
select * from car where code not in(‘c001‘,‘c002‘,‘c003‘,‘c004‘)
原文:http://www.cnblogs.com/zk0533/p/5405838.html
總結(jié)
以上是生活随笔為你收集整理的php mysql curd_Php mysql 常用代码、CURD操作以及简单查询的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql空间释放_linux 空间释放
- 下一篇: mysql errmsg unknown