Thinkphp data query and traversing array instances, thinkphp data query _ PHP Tutorial

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

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.