使用数据库
在web项目中,因为HTTP是无状态的,所以我们就需要很多东西来持久化一些数据,数据库就是一个。我们使用数据库来保存数据并且使用SQL语句来实现增删改查。这里我们默认使用MySQL数据库。下面是几个简单的操作数据库的语句:
//显示当前数据库
show databases;
//新建数据库
create database testmy;
//使用数据库
use testmy;
//新建表
create table thetest(value int);
//添加数据
insert into thetest values(111);
//查询数据
select * from thetest;
//改数据
update thetest set value=222 where value=111;
//删除数据
delete from thetest where value=222;
熟悉数据库的基本使用