thinkphp data query and traversal array instance, thinkphp data query
This article describes the methods of thinkphp data querying and iterating over arrays. Share to everyone for your reference. Here's how:
The database can be configured using the DSN method:
Copy the code as follows: ' Db_prefix ' = ' tp_ ',//Set table prefix
' Db_dsn ' = ' mysql://root: @localhost: 3306/thinkphp ',//Configure database information using DSN mode
If the two approaches exist at the same time, the DSN is preferred, and there is a simple and practical way to model it.
M () is equivalent to the new Model ();
Copy the code as follows: $m =m (' User ');//The name of the table is important to capitalize
$arr = $m->select ();
Using instances of the model can manipulate the data, the operation is generally to the database for the deletion of the search curd
Add-C Create $m->add ()
Delete-D delete $m->delete ()
Change-u Update $m->save ()
Check-R Read $m->select ()
Copy the code as follows: $m =m (' User ');//The name of the table is important to capitalize
$arr = $m->select ();//Get an array
$this->assign (' data ', $arr);//Assign a two-dimensional array to data
$this->display ();//Invoke Template
Templates can traverse arrays
Copy the Code code 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 turn on the page_trace in the debug function to help with the debugging
1. Turn on the debug function in index.php
Copy the Code code as follows: Define (' App_debug ', true);//Open Debug mode
2. Need to set configuration file config.php (home/conf/), open page trace
Copy the Code Code as follows: ' Show_page_trace ' =>true,//open page TRACE
Then the refresh will appear in the bottom right corner of the debugger console, you can view SQL, errors, processes, files and other modal information.
It is hoped that this article will be helpful to everyone's thinkphp framework design.
http://www.bkjia.com/PHPjc/919266.html www.bkjia.com true http://www.bkjia.com/PHPjc/919266.html techarticle thinkphp data query and iterate array instance, thinkphp data query This paper describes thinkphp data query and the method of traversing array. Share to everyone for your reference. The specific method is as follows ...