thinkphp data query and traversal array instance, thinkphp data Query _php tutorial

Source: Internet
Author: User

thinkphp data query and traversal array instance, thinkphp data query


This article describes the methods of thinkphp data querying and iterating over arrays. Share to everyone for your reference. Here's how:

The database can be configured using the DSN method:
Copy the code as follows: ' Db_prefix ' = ' tp_ ',//Set table prefix

' Db_dsn ' = ' mysql://root: @localhost: 3306/thinkphp ',//Configure database information using DSN mode

If the two approaches exist at the same time, the DSN is preferred, and there is a simple and practical way to model it.

M () is equivalent to the new Model ();
Copy the code as follows: $m =m (' User ');//The name of the table is important to capitalize

$arr = $m->select ();

Using instances of the model can manipulate the data, the operation is generally to the database for the deletion of the search curd

Add-C Create $m->add ()

Delete-D delete $m->delete ()

Change-u Update $m->save ()

Check-R Read $m->select ()
Copy the code as follows: $m =m (' User ');//The name of the table is important to capitalize
$arr = $m->select ();//Get an array
$this->assign (' data ', $arr);//Assign a two-dimensional array to data
$this->display ();//Invoke Template
Templates can traverse arrays
Copy the Code code as follows://vo represents the current array because it is a two-dimensional array that is read sequentially.
<{$vo .id}>----<{$vo .username}>-----<{$vo .sex}>

We can turn on the page_trace in the debug function to help with the debugging

1. Turn on the debug function in index.php
Copy the 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 the Code Code as follows: ' Show_page_trace ' =>true,//open page TRACE

Then the refresh will appear in the bottom right corner of the debugger console, you can view SQL, errors, processes, files and other modal information.

It is hoped that this article will be helpful to everyone's thinkphp framework design.

http://www.bkjia.com/PHPjc/919266.html www.bkjia.com true http://www.bkjia.com/PHPjc/919266.html techarticle thinkphp data query and iterate array instance, thinkphp data query This paper describes thinkphp data query and the method of traversing array. Share to everyone 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.