Home >Backend Development >PHP Tutorial >ThinkPHP--ActiveReocrd mode (add, delete, modify, check)

ThinkPHP--ActiveReocrd mode (add, delete, modify, check)

WBOY
WBOYOriginal
2016-08-08 09:31:221002browse

ActiveReocrd mode

The biggest feature of this mode is that it simplifies the operation of CURD and adopts an object-based operation method, which is easy to use
and understand.

//Add a piece of data

$user = M('User');
$user->user = 'Naruto';
$user->email = 'huoyin@qq.com';
$user ->date = date('Y-m-d H:i:s');

$user->add();

//Combined with create

$user = M('User');
$user-> ;create();
$user->date = date('Y-m-d H:i:s');
$user->add();

//Find the value with primary key 4

$user = M ('User');
var_dump($user->find(4));

//Find user=Crayon Shin-chan's record

$user = M('User');
var_dump($user-> ;getByUser('Crayon Shin-chan'));

//Output user

echo $user->user;

//Query multiple

$user = M('User');
var_dump($ user->select('1,2,3'));

//Modify a piece of data

$user = M('User');
$user->find(1);
$user-> ;user = 'Crayon Old New';
$user->save();

//Delete the currently found data

$user = M('User');
$user->find(11);
$user->delete();

//Delete data with primary key 10

$user = M('User');
$user->delete(10);

//Delete data with primary key 10 ,11 data

$user = M('User');
$user->delete('10,11');

The above introduces the ThinkPHP--ActiveReocrd mode (add, delete, modify and check), including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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