You can use the DSN method to configure & amp; #39; DB_PREFIX & amp; #39; & gt; & amp; #39; tp _ & amp; #39 ;, // set the table prefix & amp; #39; DB_DSN & amp; #39; & gt; & amp; #39; mysql: // root: @ localhost: 3306/thinkp...
You can use the DSN method for configuration.
'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 ();
$ 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 ()
- $ 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.
// 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.
Define ('app _ debug', true); // enable debugging mode
2. you need to set the configuration file config. php (Home/Conf/) to enable page trace.
'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.