[tp3.2.1] Data Model-Simple model connection

Source: Internet
Author: User

New Database
Database Connectivity Features
1. Write conf.php
/* Database Settings */
' Db_type ' = ', '//database type
' Db_host ' = ' + ',//server address
' Db_name ' = ', '//database name
' Db_user ' + ', '//user name
' Db_pwd ' and ' = ',//password
' Db_port ' = ', '//Port
' Db_prefix ' = ', '//database table prefix
2. read out, simply, first make a controller user, where the module method is used to connect to the database
The module base class, or M () method, is provided in 3.thinkphp to instantiate the model class.
$mod =new Model (' User ');
Use Think\model;
Access this module, controller, and operation (method), if the error is not prompted, the configuration database is correct

Note: The current database connection is usually in PDO mode.
Debugging tools provided by thinkphp
/* Database Settings */
' Db_type ' = ' pdo ',//database type
' Db_user ' = ' root ',//user name
' Db_pwd ' and ' = ',//password
' Db_prefix ' = ' think_ ',//database table prefix
' Db_dsn ' = ' Mysql:host=localhost;dbname=thinkphp;charset=utf8 ',

Turn on thinkphp debugging
"Show_page_trace" =>true,

[tp3.2.1] Data Model-Simple model connection

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.