Sql
- 命令行对数据库进行操作
-
-
- 如何进入命令行。
-
-
phpstudy_pro\Extensions\MySQL5.7.26\bin,在搜索栏内搜cmd打开命令行
mysql -u root -p//打开数据库
-
-
-
- show databases;// 进入数据库
- create database xie;// 建立一个名为xie的自己的库
- drop database xie;// 删除名为xie的库
- 库内可以由很多表,表下为字段,字段存储数据
- Use xie; //进入名为xie的库内
- Show tables;// 展示列表名
- Create table user (id int, username varchar(255),passward varchar (200));// 立列表。其中,user为表名,ID为字段名及表头int为字段名性质username也为表头括号内为长度Password也是表头255也表示长度
- Drop table user; //删除user这个表
- Desc user;//查看这个表内内容
- Alter table change password passwd varchar(32);// 更改,但是不只能更改长度和内容,这个例子是将password表头更改为passwd,长度为32
- Alert table user drop password; //删除user表内password字段
- Alter table user rename users; // 添加在username后添加password字段,把after更改为flase,就为添加在前
- Select database();//查看当前位置
- INSERT INTO users (id,username,passward) VALUES (2,’guanlaoshi’,123456);// 插入数据,其中ID后的username和password是位置第二个values内的内容是与第一个个块的内容是一一对应的
- Select * from users;//查看users表内的全部内容,其中*为全部
- 一般情况下,ID为主键,为主键的东西必须为一主键是唯一标识
- Delete from user where id=1;//
- 多个语句一起执行时,必须用分号隔开单一语句执行时,可以不用分号; ‘1’与1与(1)与(‘1’)所表达的意义相同
- Update user username=’zhanglaoshi’ where id=1;// 删除表单内容,在这个例子中是删除表名为user ID为一的内容。同时也可以在其后方加入更多的限制条件,使删除更加精确
- Select是查询库里内容,show是查询库的名称
- select username from user;// 查询username表内的内容
- select*from表名where id<2;// 查询ID小于二的内容
- select*from表名where age between30and40;//查询年龄在30到40之间的数据
- select*from表名where age=40or age=30;// 查询年龄为30或40的内容
- select*from表名where age!=30;// 查询年龄不是30的内容
- Select*from表名where age in(18,16,17);//查询年龄是18.16.17的
- Select*from表名where address like‘香%’;//查询地址是香开头的
- Select*from表名where address like‘%香’;//查询地址是香结尾的
- Select*from表名where address like‘%香%’;//查询地址含有香的
-
-
二,PHP与数据库连接
一连接数据库。
二,判断是否连接成功。
-
-
-
- 设置字符集。
-
-
四,选择数据库。
五,准备SQL语句
-
-
-
- 。六,发送SQL语句。
-
-
七,处理结果集。
-
-
-
- 八,关闭数据库
-
-