This article mainly introduces the ThinkPHP framework to implement user information query, update and delete functions, and analyzes the database configuration, control and template calling of thinkPHP framework to implement information query, update, delete and other functions in the form of examples. Friends in need You can refer to the following example
This article describes how the ThinkPHP framework implements user information query, update and delete functions. Share it with everyone for your reference, the details are as follows:
One code
1. Configuration file
false, // 关闭调试模式 'DB_TYPE'=> 'mysql', // 数据库类型 'DB_HOST'=> 'localhost', // 数据库服务器地址 'DB_NAME'=>'db_database30', // 数据库名称 'DB_USER'=>'root', // 数据库用户名 'DB_PWD'=>'root', // 数据库密码 'DB_PORT'=>'3306', // 数据库端口 'DB_PREFIX'=>'think_', // 数据表前缀 ); ?>
2. Entry file
3.Controller file
order('id desc')->limit(10)->select(); $this->assign('select',$select); // 模板变量赋值 $this->display(); // 指定模板页 } public function update(){ $db = M('User'); // 实例化模型类,参数数据表名称,不包含前缀 $select = $db->where('id='.$_GET['id'])->select(); $this->assign('select',$select); // 模板变量赋值 $this->display(update); // 指定模板页 if(isset($_POST['id'])){ $data['user'] = $_POST['user']; // 要修改的数据对象属性赋值 $data['pass'] = md5($_POST['pass']); $data['address'] = $_POST['address']; $result=$db->where('id='.$_POST['id'])->save($data); // 根据条件保存修改的数据 if($result){ $this->redirect('Index/index','', 2,'数据更新成功'); //页面重定向 } } } public function delete(){ $db = M('User'); // 实例化模型类,参数数据表名称,不包含前缀 $result=$db->where('id='.$_GET['id'])->delete(); // 删除id为5的用户数据 if($result){ $this->redirect('Index/index','', 2,'数据删除成功'); //页面重定向 } } } ?>
4. Template file one
5. Template file two
Second running results
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
ThinkPHP query statements and usage of related queries
ThinkPHP3.2.3 verification code display and Refresh and verify
Query language commonly used in ThinkPHP
The above is the detailed content of Use ThinkPHP framework to implement user information query, update and delete functions. For more information, please follow other related articles on the PHP Chinese website!