Thinkphp queries and traverses array instances, and thinkphp queries data. Thinkphp data query and traversing array instances. thinkphp data query this article describes thinkphp data query and traversing array methods. Share it with you for your reference. The specific method is as follows: thinkphp data query and traversing array instances, thinkphp data query
This article describes how to query and traverse the thinkphp data. Share it with you for your reference. The specific method is as follows:
The database can be configured using the DSN method:
The code is as follows:
'Db _ prefix' => 'TP _ ', // you can specify a table PREFIX.
'Db _ DSN '=> 'MySQL: // root: @ localhost: 3306/thinkphp', // configure database information using DSN
If the two methods exist at the same time, the DSN method is preferred, and there is a simple and practical model.
M () is equivalent to new Model ();
The code is as follows:
$ M = M ('user'); // The table name must be capitalized.
$ Arr = $ m-> select ();
A model instance can be used to operate on data. The operation generally involves adding, deleting, modifying, and querying the database CURD.
Add-C Create $ m-> add ()
Delete-D delete $ m-> Delete ()
Change-U Update $ m-> save ()
Query-R Read $ m-> select ()
The code is as follows:
$ M = M ('user'); // The table name must be capitalized.
$ Arr = $ m-> select (); // An array is obtained.
$ This-> assign ('data', $ arr); // assign a two-dimensional array to data
$ This-> display (); // call the template
The template can traverse arrays.
The code is as follows:
// Vo indicates the current array, because the two-dimensional array is read in order.
<{$ Vo. id}> ---- <{$ vo. username}> ----- <{$ vo. sex}>
We can enable page_trace in the debugging function to help with debugging.
1. enable the debugging function in index. php.
The code is as follows:
Define ('app _ debug', true); // enable debugging mode
2. you need to set the configuration file config. php (Home/Conf/) to enable page trace.
The code is as follows:
'Show _ PAGE_TRACE '=> true, // enable page Trace
Then refresh the page and a debugging platform will appear in the lower right corner of the page. you can view the adjustment information such as SQL, errors, processes, and files.
I hope this article will help you with ThinkPHP framework programming.
Examples in this article describes how thinkphp queries and traverses arrays. Share it with you for your reference. The specific method is as follows...