Mysql数据库:

常见的操作:
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
notee (\t) Don’t write into outfile.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (#) Rebuild completion hash.
source (.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don’t show warnings after every statement.

查看数据库:
在进入数据库后,使用show databases;
创建数据库:
在进入数据库后,使用create database 名字;(分号要加)
删除数据库:
在进入数据库后,使用drop database 名字;(分号要加)

    DOS命令操作数据库

创建tables是,一切都是用小括号包着的。
你想在一个库里面建表的时候 首先你要记得use 使用当前的库 use 库名;
【创建表】
create table 表名(id int ,name varchar(35),price int);
Id name table 是字段 后面的限制是类型
【删除表】
Drop table 表名字;
【查看表结构】
Desc 表名字;
【查看建表语句】
Show create database 表名字;
【查看建表语句】
Show create table 表名字;
【修改表字段值】
Alter table 表名 modify 字段名字 修改后的值;
【修改表字段】
Alter table 表名 change 原来字段名 修改后字;
(你要修该成为的类型)
【添加表字段】
Alter table 表名 add 字段名字; (字段类型)
【删除表字段】
Alter table 表名 drop 字段名字 ;
【插入顺序的问题】
First
Alter table 表名 add 你要添加的字段(字段类型) first;
After
Alter table 表名 add 你要添加的字段名字(字段类型)after;
【修改表名字】
Alter table 原表名 rename 新的名字

【数据库插入方式】;
1.insert into 表名 values(对应的元素赋值);
2.(常用的)Insert into 表名 (形参) values(实参),(实参),(实参)(可以有n个,可以添加n行);
3. Insert into 表名(形参) values(实参)(可以缺点东西;
【数据库表数据删除】:
1.delete from 表名 where 字段(username=’名字’);
【修改表中的数据】:
Update 表名 set username=’测试’ where id=1;
【查询】:
1.Select * from 表名;
2.select 表中数据 from 表名;
【去除重复值并打印】:
select distinct 表中的元素 from 表名;
———select * from 表 where id = n;
———select * from 表 GROUP BY CLASS LIMIT 0,2;(从第零个后开始数,即第一个,往后数两个并打印出来。)
———select * from 表 where age > 30 order by chengji desc limit 5,5;(可以分为三部分,第一部分将age大于30的部分筛选出来,第二将该序列倒序,最后以limit结尾)
内联,左联,右联:
注意:(两表都有相同字段才能相互关联)
【内联】:select 表1.字段,表2.字段 from 表1 inner join 表2 on 条件(例如:表1.相同字段 = 表2.相同字段);
【左联】:select 表1.字段 form 表1 left join 表2 on 条件(例如:表1.相同字段 = 表2.相同字段);(以左边的表为基准)
【右联】:select 表1.元素 form 表1 right join 表2 on 条件(例如:表1.相同字段 = 表2.相同字段);(以右边的表为基准)

【嵌套查询】
Select 字段 from 表 where 字段 in (select id from 表);
(以下的链接)(locahost/base/05/01/mysql.php)
PHP连接数据库:

  1.     链接数据库。
    

$link=mysqli_connect(‘localhost’,’root’,’’);
var_dump($link);
2.判断是否链接成功。
If(!$link){
Exit(‘数据库链接失败’);
}
3.设置字符库。
Mysqli_set_charset($link,’utf8’);
4.选择数据库。
Mysqli_select_db($link,’bbs’);
5.准备sql语句。
$sql = “select * from bbs_user”;
6.发送sql语句。
$res=Mysqli_query($link,$sql);
Var_dump($res);
7.处理结果集。
$result=Mysqli_fetch_assoc($res);
8.关闭数据库。(释放资源)
Mysqli_close($link);

如何获取其他网站的提交的信息:
$_GET[‘表单体检的name属性’];
常见函数:
1.$a=mysqli_fetch_assoc($result);(将以一个结构体以关联的方式展现出来)。
2.$a=mysqli_fetch_row($result);(将以一个结构体以索引的方式展现出来)。
3.$a=mysqli_fetch_array($result);(将以一个结构体以索引和关联的方式展现出来)。
4.$a=mysqli_num_rows($result);(直接写出有多少个结构体)。
5.$a=mysqli_affected_rows($link,$result);(直接写出有多少个结构体)。
6.$a=mysqli_insert_id($link);(返回最后插入的id值)
数据库的增删改查:
 (空格)