添加数据
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); } }
效果图: