thinkphp data query and array traversal examples, thinkphp data query_PHP tutorial

WBOY
Release: 2016-07-13 10:12:46
Original
1409 people have browsed it

thinkphp data query and array traversal instance, thinkphp data query

The example in this article describes the method of data query and array traversal in thinkphp. Share it with everyone for your reference. The specific method is as follows:

The database can be configured using the DSN method:

Copy code The code is as follows:
'DB_PREFIX'=>'tp_', //Set table prefix

'DB_DSN'=>'mysql://root:@localhost:3306/thinkphp',//Use DSN method to configure database information

If both methods exist at the same time, the DSN method is preferred, and there is also a simple and practical model method.

M() is equivalent to new Model();

Copy the code The code is as follows:
$m=M('User');//It is very important to capitalize the table name

$arr=$m->select();

You can use model instances to operate data. The operation work is generally to add, delete, modify and check the database CURD

Add -C Create $m->add()

Delete -D Delete $m->delete()

Change -U Update $m->save()

Check -R Read $m->select()

Copy the code The code is as follows:
$m=M('User');//It is very important to capitalize the table name
$arr=$m->select();//What you get is an array
$this->assign('data',$arr);//Assign a two-dimensional array to data
$this->display();//Call template

Template can traverse arrays
Copy code The code is as follows:
//vo represents the current array, because it is a two-dimensional array that is read sequentially.
<{$vo.id}>----<{$vo.username}>-----<{$vo.sex}>

We can enable page_trace in the debugging function to help with debugging

1. Turn on the debugging function in index.php

Copy code The code is as follows:
define('APP_DEBUG',true);//Enable debugging mode

2. You need to set the configuration file config.php (Home/Conf/) and enable page trace

Copy code The code is as follows:
'SHOW_PAGE_TRACE'=>true,//Open page Trace

Then refresh and the debugging console will appear in the lower right corner of the page, where you can view debugging information such as sql, errors, processes, files, etc.

I hope this article will be helpful to everyone’s ThinkPHP framework programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/919266.htmlTechArticlethinkphp data query and array traversal examples, thinkphp data query This article describes the thinkphp data query and array traversal methods. Share it with everyone for your reference. The specific method is as follows...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!