Create config. php: & lt ;? Phpif (! Defined (& amp; #39; THINK_PATH & amp; #39;) exit (); returnarray (& amp; #39; DB_TYPE & amp; #39; & gt; & amp; #39; mysql & amp; #39;, // database class...
Create config. php in the project Root Directory:
- If (! Defined ('think _ path') exit ();
- Return array (
- 'Db _ type' => 'mysql', // Database TYPE
- 'Db _ host' => 'localhost', // HOST
- 'Db _ name' => 'aoli', // database NAME
- 'Db _ user' => 'root', // database username
- 'Db _ pwd' => '', // database password
- 'Db _ prefix' => '', // data table PREFIX
- 'Db _ charset' => 'utf8', // website code
- 'Db _ port' => '123', // database PORT
- );
- ?>
\ Home \ Conf \ config. php
- $ Arr1 = array {
- 'URL _ model' => 2, // pathinfo access mode
- };
- $ Arr2 = include './config. php ';
- Return array_merge ($ arr1, $ arr2); // array integration
- ?>
\ Admin \ Conf \ config. php
- $ Arr1 = array {
- 'URL _ model' => 1, // get mode in normal access mode
- };
- $ Arr2 = include './config. php ';
- Return array_merge ($ arr1, $ arr2); // array integration
- ?>
Master/slave database settings
Suitable for high concurrency and high load. you can view the default system constant settings in \ ThinkPHP \ Common \ convention. php.
Config. php
- Return array (
- // 'Config maps '=> 'configuration value'
- // Background
- 'URL _ mode' => 0,
- 'Db _ type' => 'mysql ',
- 'Db _ host' => 'localhost, 192.168.1.2 ', // Two database servers
- 'Db _ port' => '123 ',
- 'Db _ name' => 'thinkphptest', // You do not need to define multiple database names if they are the same. if they are different, they correspond to the server in sequence.
- 'Db _ user' => 'root ',
- 'Db _ pwd' => 'password ',
- // Table prefix
- 'Db _ prefix' => 'think _',
- // Configure the master-slave database
- 'Db _ DEPLOY_TYPE '=> 1, // enable distributed database
- 'Db _ RW_SEPARATE '=> ture, // read/write splitting. the first server is the write server by default, and the others are read-only but not written.
- );
- ?>
Read database file parameters in an action:
- $ Hh = C ('Db _ host'); // C can read values in the configuration file
- $ Pp = C ('Db _ prefix ');
- $ This-> assain ('H', $ hh );
- $ This-> assain ('P', $ pp );
- $ This-> display ();
Tpl under this action:
Database server address: {$ h}
Database table prefix: {$ p}