This article describes the thinkphp data query and traversal array method. Share to everyone for your reference. The specific methods are as follows:
The database can be configured using the DSN method:
Copy Code code as follows:
' Db_prefix ' => ' tp_ ',//Set table prefix
' Db_dsn ' => ' mysql://root: @localhost: 3306/thinkphp ',//Configure database information using DSN
If both approaches are present, the DSN approach takes precedence, and there is a simple, practical way to model.
M () is equivalent to new Model ();
Copy Code code as follows:
$m =m (' User ');//table name to capitalize is very important
$arr = $m->select ();
Use the example of the model to be able to manipulate the data, the work of the operation is to the database to carry on the enhancement to check curd
Add-C Create $m->add ()
Delete-D delete $m->delete ()
Change-u Update $m->save ()
Check-R Read $m->select ()
Copy Code code as follows:
$m =m (' User ');//table name to capitalize is very important
$arr = $m->select ();//Get an array
$this->assign (' data ', $arr);//Assign a two-dimensional array to data
$this->display ()//Call template
templates can traverse arrays
Copy Code code as follows:
VO represents the current array, because a two-dimensional array is read sequentially.
<{$vo .id}>----<{$vo .username}>-----<{$vo .sex}>
We can turn on the page_trace in the debugging function to help with debugging
1. Open the debugging function in the index.php
Copy 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 Code code as follows:
' Show_page_trace ' =>true,//open page TRACE
The refresh will then appear in the lower-right corner of the page, and you can view SQL, errors, processes, files, and other modal information.
I hope this article will be helpful to everyone's thinkphp framework program design.