TP5 数据库的增删改查
添加数据
CREATE TABLE IF NOT EXISTS `think_data` ( `id` int(8) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL COMMENT '名称', `status` tinyint(2) NOT NULL DEFAULT '0' COMMENT '状态', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ; INSERT INTO `think_data` (`id`, `name`, `status`) VALUES (1, 'onestopweb', 1), (2, '吴者然', 1), (3, 'chaoyi', 1);
application\index\controller\Index.php
<?php namespace app\index\controller; use think\Db; class Index { public function index() { // 后面的数据库查询代码都放在这个位置 // 插入记录 //$result = Db::execute('insert into think_data (id, name ,status) values (5, "onestopweb",1)'); //dump($result); // 更新记录 //$result = Db::execute('update think_data set name = "chaoyi" where id = 5 '); //dump($result); // 查询数据 //$result = Db::query('select * from think_data where id = 5'); //dump($result); // 删除数据 //$result = Db::execute('delete from think_data where id = 5 '); //dump($result); // 批量查询数据 $result = Db::query('select * from think_data'); dump($result); } }
效果图:
相关推荐
lbyd0 2020-11-17
sushuanglei 2020-11-12
腾讯soso团队 2020-11-06
gaobudong 2020-11-04
yangkang 2020-11-09
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
wushengyong 2020-10-28
lizhengjava 2020-11-13
星月情缘 2020-11-13
huangxiaoyun00 2020-11-13
luyong0 2020-11-08
Apsaravod 2020-11-05
PeterChangyb 2020-11-05
wwwjun 2020-11-02
gyunwh 2020-11-02
EchoYY 2020-10-31
dingyahui 2020-10-30