thinkphp data querying and traversing an array instance _php instance

Source: Internet
Author: User
Tags dsn

This article describes the thinkphp data query and traversal array method. Share to everyone for your reference. The specific methods are as follows:

The database can be configured using the DSN method:

Copy Code code as follows:
' Db_prefix ' => ' tp_ ',//Set table prefix

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

If both approaches are present, the DSN approach takes precedence, and there is a simple, practical way to model.

M () is equivalent to new Model ();

Copy Code code as follows:
$m =m (' User ');//table name to capitalize is very important

$arr = $m->select ();

Use the example of the model to be able to manipulate the data, the work of the operation is to the database to carry on the enhancement to check curd

Add-C Create $m->add ()

Delete-D delete $m->delete ()

Change-u Update $m->save ()

Check-R Read $m->select ()

Copy Code code as follows:
$m =m (' User ');//table name to capitalize is very important
$arr = $m->select ();//Get an array
$this->assign (' data ', $arr);//Assign a two-dimensional array to data
$this->display ()//Call template

templates can traverse arrays
Copy Code code as follows:
VO represents the current array, because a two-dimensional array is read sequentially.
<{$vo .id}>----<{$vo .username}>-----<{$vo .sex}>

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

1. Open the debugging function in the index.php

Copy 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 Code code as follows:
' Show_page_trace ' =>true,//open page TRACE

The refresh will then appear in the lower-right corner of the page, and you can view SQL, errors, processes, files, and other modal information.

I hope this article will be helpful to everyone's thinkphp framework program design.

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.