thinkphp model Initialization Instance Analysis _php instance

Source: Internet
Author: User
This paper describes the method of thinkphp model initialization. Share to everyone for your reference, as follows:

/*  $dsn = ' mysql://bookman:book123@localhost:3306/weapons ';  $guns _tab = M (' Guns ', ' ', $dsn);  $gun 1 = $guns _tab->select ();  echo $guns _tab-Getlastsql ();  Dump ($gun 1); *//*  $guns _tab = M (' Guns ');  $gun 1 = $guns _tab->select ();  echo $guns _tab-Getlastsql ();  Dump ($gun 1); */  $guns _tab = new Gunsmodel ();  $gun 1 = $guns _tab->select () page (' n ');  echo $guns _tab-Getlastsql ();  Dump ($gun 1);  $guns _tab-Showinfo ();/*  $guns _tab = new Detectmodel (' Guns ');  $gun 1 = $guns _tab select ();  echo $guns _tab-Getlastsql ();  Dump ($gun 1);  $guns _tab-Showinfo (); * *

1. How to connect from a configuration file

$dsn = ' mysql://bookman:book123@localhost:3306/weapons '; $guns _tab = M (' Guns ', ' ", $DSN); $gun 1 = $guns _tab->select () ; Echo $guns _tab-getlastsql ();d UMP ($gun 1);

2. Connect to the database according to the configuration file, the table name must distinguish clearly

$guns _tab = M (' Guns '), $gun 1 = $guns _tab->select (); Echo $guns _tab, Getlastsql ();d UMP ($gun 1);

3. I have a custom model that implements my own business methods, and I have a guns table so that I can initialize the model like this. You can get the data from the guns table, and you can also use the business methods in my custom model.

$guns _tab = new Detectmodel (' Guns '), $gun 1 = $guns _tab, select (), Echo $guns _tab, Getlastsql ();d UMP ($gun 1); $guns _tab, Showinfo ();

It is hoped that this article is helpful to the PHP program design based on 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.