Basic operation of the TP framework link database

Source: Internet
Author: User

<?PHPnamespaceAdmin\controller; use Think\controller; classMaincontroller extends Controller { Publicfunction Showlist () {echo"Big Apple Mall"; }
     Publicfunction Test () {//Data Access//Build Model Objects$nation = D ("Nation"); //Enquiry//$a = $nation->select ();//check all, return associative array//$a = $nation->select ("n001"); //$a = $nation->select ("n001,n002");//The Select method is checked by the primary key value.//$a = $nation->find ("n002");//Find method can look up a piece of data//consistent Operation//$a = $nation->where ("Name= ' Miao '")->select ();//where represents the condition//$a = $nation->where ("Name= ' Han ' or name= ' Manchu '")->select ();//multiple conditions can be written//$a = $nation->table ("Car")->select ();//table can be used to switch tables//$a = $nation->table ("Car")->field ("name")->select ();//$a = $nation->field ("name")->select ();//field method for querying fields//$a = $nation->table ("Car")->order ("Code desc")->select ();//Order for sorting//$a = $nation->table ("Car")->limit (3,3)->select ();//Limit Paging method limit (3,3) means skipping 3 strips to fetch 3//$a = $nation->table ("Car")->page (3,3)->select ();//Page (3,3) means 3rd 3rd article//$a = $nation->table ("Car")->field ("Brand,avg (Price)")->group ("Brand")->select ();//Group query: Query the classification of the average price of different classes named Brand//$a = $nation->table ("Car")->field ("Brand,avg (Price)")->group ("Brand")->having ("avg (PRICE>50)") )->select ();//Group query: Query the classification of different classes named brand with average price greater than 50//$a = $nation->alias (' a ')->field ("B.code as ' Code ', b.name as ' Name ', a.name as ' national ')->join (" Info B on a.code= B.nation ")->select ();//Conditional Query//$a = $nation->table (' car ')->distinct (True)->field (' brand ')->select ();//distinct is to go to re-query: The query indicates that the list in car for brand to go heavy//$a = $nation->where ("code= ' n001 '")->getfield ("name");//GetField is the value of a column (which indicates that the name column in the Nation column is named code=n001)//$a = $nation->count ();//count indicates a few data in the Nation table//$a = $nation->table ("Car")->avg (price);//The Avg method represents the average number of columns (price) in the car table.//$a = $nation->table ("Car")->max (price);//The Max method represents the maximum value of the column (price) in the car table//$a = $nation->table (' car ')->min (price);//The min method represents the minimum value of the column (price) in the car table//$a = $nation->table (' car ')->sum (price);//The /sum method represents the sum of the columns (price) in the car table//$sql = "SELECT * from info";//You can use the original SQL statement//$a = $nation->query ($sql);//query statements are executed using the Queries method//$sql = "INSERT into nation values (' n011 ', ' Korean ')"; //$a = $nation->execute ($sql);//Execute means to perform additions, deletions, changes//var_dump ($a); //$attr =array ("Code" = "n012", "Name" = "Dulong");//Array mode: Must be an associative array//$a = $nation->add ($attr);//add data in the form of an array//var_dump ($a);//If 1 is returned successfully//Add using AR Method (Entity class database access Class connection Class)//$nation->code= "n087"; //$nation->name= "Russian"; //$nation->add (); //indicates a 5-second jump to the registration page if the registration is successful (comment the 237 lines in/thinkphp/lrbrary/think/db/lite.class.php)//$this->redirect (' Zhuce ', Array (), 5, ' page jump ... ');
        
        
        
    }
     Publicfunction Zhuce () {//Implement two logic//1. Display registration page 2. Add content to the database
    if(Empty ($_post)) {//Show Page$ This-Show (); }
        Else{$n=d ("Nation"); $n->create ();//Automatic collection of forms must have post data
        
        ///$n->name= "Hello";
$z= $nAdd (); if($z) {//Show Page$ This->success ("Add Success","Zhuce"); }
        Else
            {
        //the default jump for the error page is to return to the previous page, usually without setting$ This->error ("Add failed! "); }
        }    
        
    }
    
     Publicfunction Canshu ($id =0)
    {
    //Pass-through value: 1. Can write directly//$id =$_get["id"]; //echo $id; //2. Can give a formal parameter ($id =0)
echo $id; }
     
}

Error (Comment 237 lines in/thinkphp/lrbrary/think/db/lite.class.php)

Basic operation of the TP framework link database

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.