Home >PHP Framework >YII >Can yii2 connect to db2?
A project will require connecting to multiple databases as needed. The operation process in the actual project is recorded here. Including the configuration of database connection and how to generate model files and use them in the controller. (Recommended learning: yii framework)
Configuration
Open the database configuration file common\config\main-local.php, in Add db2 under the original db configuration item (the name can be chosen by yourself and cannot be repeated with other database names), and configure the properties of the second database
The above configuration can complete the function of yii2 connecting to multiple databases, but you still need to pay attention to the actual application
Generate the model through gii, what needs to be paid attention to here is the database connection ID To change to db2 (fill in the English name of the second database library you set in main_local)
The above is the detailed content of Can yii2 connect to db2?. For more information, please follow other related articles on the PHP Chinese website!