ThinkPHP data table operation_PHP tutorial
Reading of data Read
$m=new Model('User');
$m=M('User');
select
$m->select();//Get all data and return it in array form
find
$m->find($id);//Get a single piece of data
getField(field name)//Get a specific field value
$arr=$m->where('id=2')->getField('username');
3. Create data in ThinkPHP 3 (Key points)
Adding data Create
$m=new Model('User');
$m=M('User');
$m->field name=value
$m->add();
The return value is the new id number
4. Delete data in ThinkPHP 3 (Key points)
$m=M('User');
$m->delete(2); //Delete the data with id 2
$m->where('id=2')->delete(); //Same effect as above, also deletes the data with id 2
The return value is the number of affected rows
5. ThinkPHP 3 update data (key points)
$m=M('User');
$data['id']=1;
$data['username']='ztz2';
$m->save($data);
The return value is the number of affected rows
============================================
1. Ordinary query methods
2. Expression query method
3. Interval query
4. Statistical query
5. SQL direct query
1. Ordinary query methods
a. String
$arr=$m->where("sex=0 and username='gege'")->find();
b. Array
$data['sex']=0;
$data['username']='gege';
$arr=$m->where($data)->find();
Note: This method defaults to an and relationship. If you use an or relationship, you need to add an array value
$data['sex']=0;
$data['username']='gege';
$data['_logic']='or';
2. Expression query method
$data['id']=array('lt',6);
$arr=$m->where($data)->select();
EQ equals
NEQ is not equal to
GT is greater than
EGT is greater than or equal to
LT is less than
ELT is less than or equal to
LIKE fuzzy query
$data['username']=array('like','%ge');
$arr=$m->where($data)->select();
NOTLIKE
$data['username']=array('notlike','%ge%'); //There is no space in the middle of notlike
$arr=$m->where($data)->select();
Note: If a field needs to match multiple wildcard characters
$data['username']=array('like',array('%ge%','%2%','%五%'),'and');//If there is no third value, the default The relationship is or relationship
$arr=$m->where($data)->select();
BETWEEN
$data['id']=array('between',array(5,7));
$arr=$m->where($data)->select();
//SELECT * FROM `tp_user` WHERE ( (`id` BETWEEN 5 AND 7 ) )
$data['id']=array('not between',array(5,7));//Note, there must be a space between not and between
$arr=$m->where($data)->select();
IN
$data['id']=array('in',array(4,6,7));
$arr=$m->where($data)->select();
//SELECT * FROM `tp_user` WHERE ( `id` IN (4,6,7) )
$data['id']=array('not in',array(4,6,7));
$arr=$m->where($data)->select();
//SELECT * FROM `tp_user` WHERE ( `id` NOT IN (4,6,7) )
3. Interval query
$data['id']=array(array('gt',4),array('lt',10));//The default relationship is the relationship of and
//SELECT * FROM `tp_user` WHERE ( (`id` > 4) AND (`id`
$data['id']=array(array('gt',4),array('lt',10),'or') //The relationship is the relationship of or
$data['name']=array(array('like','%2%'),array('like','%五%'),'gege','or');
4. Statistical query
count //Get the number
max //Get the maximum number
min //Get the minimum number
avg //Get the average
sum //Get the sum
5. SQL direct query
a. Query is mainly used for data processing
Result set of successfully returned data
Returns boolean false
on failure$m=M();
$result=$m->query("select * from t_user where id >50");
var_dump($result);
b. execute is used to update a write operation
Successfully returns the number of affected rows
Returns boolean false
on failure$m=M();
$result=$m->execute("insert into t_user(`username`) values('ztz3')");
var_dump($result);

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





How to set up keyboard startup on Gigabyte's motherboard. First, if it needs to support keyboard startup, it must be a PS2 keyboard! ! The setting steps are as follows: Step 1: Press Del or F2 to enter the BIOS after booting, and go to the Advanced (Advanced) mode of the BIOS. Ordinary motherboards enter the EZ (Easy) mode of the motherboard by default. You need to press F7 to switch to the Advanced mode. ROG series motherboards enter the BIOS by default. Advanced mode (we use Simplified Chinese to demonstrate) Step 2: Select to - [Advanced] - [Advanced Power Management (APM)] Step 3: Find the option [Wake up by PS2 keyboard] Step 4: This option The default is Disabled. After pulling down, you can see three different setting options, namely press [space bar] to turn on the computer, press group

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

1. Processor When choosing a computer configuration, the processor is one of the most important components. For playing games like CS, the performance of the processor directly affects the smoothness and response speed of the game. It is recommended to choose Intel Core i5 or i7 series processors because they have powerful multi-core processing capabilities and high frequencies, and can easily cope with the high requirements of CS. 2. Graphics card Graphics card is one of the important factors in game performance. For shooting games such as CS, the performance of the graphics card directly affects the clarity and smoothness of the game screen. It is recommended to choose NVIDIA GeForce GTX series or AMD Radeon RX series graphics cards. They have excellent graphics processing capabilities and high frame rate output, and can provide a better gaming experience. 3. Memory power

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

SPDIFOUT connection line sequence on the motherboard. Recently, I encountered a problem regarding the wiring sequence of the wires. I checked online. Some information says that 1, 2, and 4 correspond to out, +5V, and ground; while other information says that 1, 2, and 4 correspond to out, ground, and +5V. The best way is to check your motherboard manual. If you can't find the manual, you can use a multimeter to measure it. Find the ground first, then you can determine the order of the rest of the wiring. How to connect motherboard VDG wiring When connecting the VDG wiring of the motherboard, you need to plug one end of the VGA cable into the VGA interface of the monitor and the other end into the VGA interface of the computer's graphics card. Please be careful not to plug it into the motherboard's VGA port. Once connected, you can

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.
