Thinkphp data query and traversal array

Source: Internet
Author: User
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 ()

  1. $ M = M ('user'); // The table name must be capitalized.
  2. $ Arr = $ m-> select (); // An array is obtained.
  3. $ This-> assign ('data', $ arr); // assign a two-dimensional array to data
  4. $ 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.