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