ThinkPHP model initialization instance Analysis _ PHP

Source: Internet
Author: User
This article mainly introduces the thinkPHP model initialization method, and analyzes thinkPHP model initialization and database operation related skills in the form of instances. it has some reference value. if you need ThinkPHP, you can refer to thinkPHP.

This document describes how to initialize the thinkPHP model. We will share this with you for your reference. The details are as follows:

/*  $dsn = 'mysql://bookman:book123@localhost:3306/Weapons';  $guns_tab = M('guns','',$dsn);  $gun1 = $guns_tab ->select();  echo $guns_tab -> getLastSql();  dump($gun1);*//*  $guns_tab = M('guns');  $gun1 = $guns_tab ->select();  echo $guns_tab -> getLastSql();  dump($gun1);*/  $guns_tab = new GunsModel();  $gun1 = $guns_tab ->select() -> page('1,1');  echo $guns_tab -> getLastSql();  dump($gun1);  $guns_tab -> showInfo();/*  $guns_tab = new DetectModel('guns');  $gun1 = $guns_tab -> select();  echo $guns_tab -> getLastSql();  dump($gun1);  $guns_tab -> showInfo();*/

1. disconnection from the configuration file

$dsn = 'mysql://bookman:book123@localhost:3306/Weapons';$guns_tab = M('guns','',$dsn);$gun1 = $guns_tab ->select();echo $guns_tab -> getLastSql();dump($gun1);

2. connect to the database according to the configuration file. The table names must be clearly distinguished.

$guns_tab = M('guns');$gun1 = $guns_tab ->select();echo $guns_tab -> getLastSql();dump($gun1);

3. I have a custom model that implements my own business methods. I also have a guns table that can initialize the model in this way. You can obtain the data in the guns table or use the business methods in the custom model.

$guns_tab = new DetectModel('guns');$gun1 = $guns_tab -> select();echo $guns_tab -> getLastSql();dump($gun1);$guns_tab -> showInfo();

I hope this article will help you design PHP programs based on the thinkPHP framework.

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.