ThinkPHP3.2.3 New Features of database settings

Source: Internet
Author: User
In the previous article, we summarized the new changes in ThinkPHP3.2. In this article, we will take a detailed look at the new features of the database, which are very detailed. If you need them, refer to them.

In the previous article, we summarized the new changes in ThinkPHP3.2. In this article, we will take a detailed look at the new features of the database, which are very detailed. If you need them, refer to them.

The database driver of ThinkPHP3.2.3 is completely rewritten using PDO. The configuration and usage are more flexible and powerful than the previous version. Let's take a look at how to use it.

First, the database configuration information of 3.2.3 has been adjusted. The complete database settings include:

The Code is as follows:


/* Database settings */
'Db _ type' => '', // Database TYPE
'Db _ host' => '', // server address
'Db _ name' => '', // Database NAME
'Db _ user' => '', // USER Name
'Db _ pwd' => '', // Password
'Db _ port' => '', // PORT
'Db _ prefix' => '', // database table PREFIX
'Db _ PARAMS '=> array (), // database connection Parameters
'Db _ debug' => TRUE, // you can record SQL logs after enabling the database debugging mode.
'Db _ LITE '=> false, // use the Lite mode of the database.
'Db _ FIELDS_CACHE '=> true, // enable field caching
'Db _ charset' => 'utf8', // The database encoding uses 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 master-slave mode is valid for database read/write splitting
'Db _ MASTER_NUM '=> 1, // Number of Master servers after read/write splitting
'Db _ slave_no' => '', // specify the serial number of the slave server

The following parameters are removed from version 3.2.2:

The Code is as follows:


'Db _ FIELDTYPE_CHECK '// 3.2.3 forcibly checks the field type.
'Db _ SQL _BUILD_CACHE '// 3.2.3 cancels SQL creation Cache
'Db _ SQL _BUILD_QUEUE '// 3.2.3 cancels SQL creation Cache
'Db _ SQL _BUILD_LENGTH '// 3.2.3 cancels SQL creation Cache
'Db _ SQL _LOG '// replaced by the new DB_DEBUG Parameter
'Db _ BIND_PARAM '// The new version uses PDO to automatically bind parameters without setting

The new database settings include:

The Code is as follows:


'Db _ debug' // used to enable the database debugging mode. After enabling this mode, you can record SQL logs.
'Db _ LITE '// whether to enable the database Lite mode connection. Only native SQL queries can be used.

3.2.2 The debugging mode of the database version and the debugging mode of the project (defined by the APP_DEBUG constant) are bound. The debugging mode of the database version starting from 3.2.3 is set independently (set by the DB_DEBUG parameter.

The DB_TYPE parameter is used to set the database type. Currently, the supported drivers include mysql, sqlite, oracle, pgsql, sqlsrv, and firebird (drivers need to be added for other database types). The settings are as follows:
'Db _ type' => 'mysql', // It cannot be set to PDO or be different from mysql or mysqli.

Database connection information, including the following parameters:

The Code is as follows:


'Db _ host' => '', // ip address used for the server address
'Db _ name' => '', // Database NAME
'Db _ user' => '', // USER Name
'Db _ pwd' => '', // Password
'Db _ port' => '', // If the PORT is left empty, the default PORT is used.
'Db _ charset' => '', // database Encoding

The preceding parameters are automatically converted to the PDO connection parameters when the PDO instance is instantiated.

DB_DSN parameters generally do not need to be set. The system's database driver will perform the default settings. If you need to adjust the parameters, follow the DSN settings of the relevant database connection of PDO.

DB_PARAMS is used to set database connection parameters. The fourth parameter of PDO instantiation is passed in.

The following is a typical Global Database Configuration:

The Code is as follows:

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.