


How to implement addition, deletion, modification and query in thinkphp3
This article will introduce you to the addition, deletion, modification and search operations under the ThinkPHP3 framework. I hope it will be helpful to developers who are learning the ThinkPHP3 framework.
- Add operation
In ThinkPHP3, you can use the M method to add a piece of data, for example:
$Model = M('User'); $data['name'] = 'wuzhi'; $data['password'] = md5('123456'); $result = $Model->add($data);
The above code means to instantiate the User model , and set the name and password attributes for it, and then insert the data into the database through the add method. $result is the primary key value returned after insertion.
- Query operation
To query a single data, use the find method, to query multiple data, use the select method, for example:
$Model = M('User'); $condition['id'] = 1; $result = $Model->where($condition)->find();
The above code means query id User data of 1 and return the result.
$Model = M('User'); $condition['id'] = array('between',array(1,10)); $result = $Model->where($condition)->select();
The above code queries user data with IDs between 1-10 and returns the results.
- Modification operation
Use the save method to modify existing data, for example:
$Model = M('User'); $condition['id'] = 1; $data['name'] = 'lisi'; $data['password'] = md5('654321'); $result = $Model->where($condition)->save($data);
The above code will change the name and The password is changed to lisi and 654321.
- Delete operation
Use the delete method to delete data, for example:
$Model = M('User'); $condition['id'] = 1; $result = $Model->where($condition)->delete();
The above code deletes the user data with id 1.
The above is a basic introduction to the addition, deletion, modification and search operations under the ThinkPHP3 framework. In actual development, we need to flexibly use the above methods to achieve various functions. I hope this article can help everyone.
The above is the detailed content of How to implement addition, deletion, modification and query in thinkphp3. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

