PHP学习之[第08讲]数据库MySQL基础之增删改查

一、工具:

1、phpMyAdmin (http://www.phpmyadmin.net/)

2、Navicat (http://www.navicat.com/)  

3、MySQL GUI Tools (http://dev.mysql.com/downloads/gui-tools/

二、语法:

数据类型

描述

应用范围

int,smallint

整型,常用int型,取值最大11位

点击量,编号,真假

char ,varchar

字符串型,char最大取值255字节,varchar更长并伸缩

标题,姓名,关键字

Date,datime

日期型,固定格式:

0000-00-00 00:00:00

 

float ,double

小数类型,一般设置类型为

(总长度,小数位长度)

价格,科学数值等

Text,longtext

备注型:没有长度限制,但取决于服务器和mysql性能

新闻内容,长内容

Insert into 表 (字段1,字段2…values (1,值2)

Insert into 表  values (1,值2)

Insert into 表  set 字段1=1,字段2=2……

Select 字段,字段,…… from   表 

Select   *  或  函数(字段) from 

  count*)  //统计条数

  sum (字段)   //求和

  avg(字段)//求平均值

  max(字段)//求最大值

  min (字段)//求最小值

Select 字段,字段,…… from   where   条件 

字段 【 条件运算符】  值如: =  ,  >  ,  <   ,  <>  ,  and  ,  or   

函数:replace()

Select 字段,字段,…… from   表  where  字段  like ‘%%’  

Select 字段,字段,…… from   表  where  字段  not like ‘%%’  

Select 字段,字段,…… from   表  where  字段  in  (值,值)

Select 字段,字段,…… from   表  where  字段  not  in (值,值)

Select 字段,字段,…… from   表  group by 字段 

Select 字段,字段,…… from   表  order by 字段 [asc / desc ]

Select 字段,字段,…… from   表    limit    起始位   ,条数

Select *  from   user where age<30 group by job order by id desc limit 10

Update set 字段=值 , 字段=值  [where] [group] [order] [limit] 

delete from [where] [group] [order] [limit] 

posted @ 2015-06-19 17:53  GreyWolf  阅读(225)  评论(0编辑  收藏  举报