mysql对大小写不敏感

 

MySQL --- 库 ---- 表 ----字段 (类型和内容)

 

 

对数据库的操作,注意 ``````tab上面的 小引号(``)的使用

 插入

// 增
Insert into 表 (字段1,字段2....) values (值1, 值2)

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

查询

// 查
Select 字段, 字段 ... from 表

Select * 或  函数(字段)  from 表

// 其中部分函数如下
      
//  查
Select  字段,字段 .... from 表 where 条件    // 条件的实例:id=5或者 id<6
// 模糊查询  %表示匹配任意字符任意次数
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(倒序)]  // order by id asc , name desc

// 指定位置查询
Select  字段,字段...  from 表 limit 起始位,条数
    

   查询的规则:多个情况组合的时候,遵循WGOL规范(Where / Group by / Order by / Limit)

//  查询表user
// 规则:id倒序 age小于30岁 不重复职业job  取前10条

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]

 

 

 

 

// 连接mysql
mysql_connect(数据库地址,用户名,密码)

// 连接某个数据库
mysql_select_db(数据库名)

// 设置数据库编码格式
mysql_set_chartset('编码')           //  php5.2.3版本
mysql_query("set names ' 编码 ' ")   //  通用

// 保证三码合一:数据库DB  视图 view  代码code

 

// 用php来操作mysql,返回资源类型
mysql_query(SQL语句或者命令)

// 处理资源数据  返回数组类型
mysql_fetch_array(资源数据)  // 返回下标与键名数组
mysql_fetch_row(资源数据)  // 返回下标数组
mysql_fetch_object(资源数据)  // 返回对象形式调用

// 获取数据库的数据条数  返回init类型
mysql_num_rows(数据资源)

// 关闭数据库
mysql_close(数据资源)

 

posted on 2017-01-11 11:24  一直在寻  阅读(274)  评论(0)    收藏  举报