PHP 本地 数据库 sqlite3 使用


如果你不想要使用mysql,Oracle这样的数据库,有想要实现数据存储,有没有解决方案?当然有,那就来看看sqlite3怎么操作的吧


常见命令

先从常见命令入手,熟悉下面的命令,有助于你快速上手sqlite3.

sqlite3 <*.db> //打开数据库
.help //显示所有命令
.quit //退出sqlite3:
.database //显示当前打开的数据库
.tables //显示数据库中所有表名
.schema [table_name] //查看表的结构

注意:这些命令都是以 ” . “开头的


sqlite常用语句

创建新表

create  table  <table_name>  (f1  type1, f2  type2,…);

// 例如: create table  people(id,name,age);

删除表

drop  table  <table_name>;

// 例如:   drop table people;

添加记录

insert  into  <table_name>  values (value1, value2,…);

// 例如:    insert into people  values(1,'A',10);

查询记录

select  *  from  <table_name>  where  <expression>;

// 例如:  select  *  from  people  where  name='A';

删除记录

delete  from  <table_name>  where  <expression>;

// 例如:  delete from pople  where name='C';

更新记录

update  <table_name>  set  <key=value>,…   where  <expression>;  

// 例如:  update  people set  name='wch'  where  id=4 and  age=15;

在表中添加字段

alter table <table> add column <field> ;

// 例如:  alter table  people add column addr;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值