Home Backend Development PHP Tutorial ThinkPHP data table operation_PHP tutorial

ThinkPHP data table operation_PHP tutorial

Jul 13, 2016 am 10:42 AM
thinkphp data sheet of

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);


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/635021.htmlTechArticleReading data Read $m=new Model('User'); $m=M('User '); select $m->select();//Get all data and return it as an array find $m->find($id);//Get a single piece of data getField(field name...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set up the keyboard boot function on a GIGABYTE motherboard (enable keyboard boot mode on GIGABYTE motherboard) How to set up the keyboard boot function on a GIGABYTE motherboard (enable keyboard boot mode on GIGABYTE motherboard) Dec 31, 2023 pm 05:15 PM

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

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

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.

The first choice for CS players: recommended computer configuration The first choice for CS players: recommended computer configuration Jan 02, 2024 pm 04:26 PM

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

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

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.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

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.

Digital audio output interface on the motherboard-SPDIF OUT Digital audio output interface on the motherboard-SPDIF OUT Jan 14, 2024 pm 04:42 PM

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 Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Nov 22, 2023 pm 12:01 PM

"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.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

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.

See all articles