(1) Configuring database connections
The connection configuration of the database can be found in the system configuration file thinkphp/conf/convention.php
/*Database Settings*/' Db_type ' = ',//database type, typically MySQL ' Db_host ' = ',//server address, localhost for local development, remote for remote IP ' Db_name ' = ',//Database name' Db_user ' = ',//User name' Db_pwd ' = ',//Password' Db_port ' = ',//Port,3306. If you fill out MySQL, you can not fill in the ' Db_prefix ' = ',//The database table prefix. For example, Sp_user, the prefix is sp. As for the reason in the article made introduction' Db_params ' =Array(),//Database Connection Parameters' Db_debug ' =TRUE,//SQL log can be logged when database debug mode is turned on' Db_fields_cache ' =true,//Enable field caching' Db_charset ' = ' UTF8 ',//database encoding is UTF8 by default' Db_deploy_type ' = 0,//Database Deployment method: 0 Centralized (single server), 1 distributed (Master-slave server)' Db_rw_separate ' =false,//whether the database reads and writes separate master-slave valid' Db_master_num ' = 1,//number of master servers for read-write separation' Db_slave_no ' = ',//Specify the number from the server
Can not be changed directly in the system configuration file, should be placed in the corresponding configuration file. The configuration file, in addition to the system configuration file, also has a grouping/platform profile and an application configuration file.
So what level of configuration file does the database configuration file location put in?
In actual development, the front desk background generally uses a database, that is, a project a database, so an application using a database, so put to the application level configuration file application\common\conf\config.php
In
<?PHPreturn Array( //' Config item ' = ' config value ' /*Database Settings*/' Db_type ' = ' mysql ',//database type, in addition to the possibility of using ACCESS,ORACLE,SQLITE,DB2' db_host ' = ' localhost ',//server address, if remote server, fill in the remote IP' Db_name ' = ' Db_oa ',//Database name' Db_user ' = ' root ',//User name' Db_pwd ' = ' root ',//Password' Db_port ' = ' 3306 ',//Port' Db_prefix ' = ' sp_ ',//database table prefix, must be underlined when set);
(2) Create DATABASE and data tables
Database name: Db_oa
Data table Name: Sp_dept (Department department);
Prepare the SQL statement:
CREATE DATABASE db_oa;// Usedb_oa;//Call Database CREATE TABLE sp_dept (ID int notNULLAuto Increment,name varchar (() notNULL,PID int notNULL default0,//Division of the subordinate, PID only subordinate Department IDSortint notNULL default50,//sortRemark varchar (255),//Remarks descriptionPrimaryKey(ID)) engine=myisamdefaultcharset=utf8;//default storage engine for engine Myisam,mysql
Knowledge Point: Not NULL is not empty; auto increment self-increment; default defaults;
In addition to the command line cmd creation, you can also use Navicat Premium. It is a multi-connection database management tool that allows you to connect to MySQL, SQL Server, SQLite, Oracle,
PostgreSQL database makes it easier to manage different types of databases. Specific creation and use I made a summary in the article http://570109268.iteye.com/admin/blogs/2414848
Video Learning Transcript---thinkphp---thinkphp model (M)