Home > Article > PHP Framework > How to switch database in thinkphp323 model
When processing programs, we often encounter data that needs to be processed in different databases, so we need to connect two different databases. So how to switch databases in the model?
1. First create a data model.
#2. Create a new method in the model to query the data of the table in the data and return it.
3. Also create a method in the controller to print out the data returned by calling the method in the model.
4. There are two different ways to connect two different databases sww3 and book
in the module configuration file.5. Use table member to connect data DB_CONFIG1 in the model, and use DB_CONFIG2 to connect data 2 to link data table blog_category
6. Use the browser to control and comment out the code for connecting data 2. First, only connect to database 1 to view the running results.
7. Use browser control and comment out the code connecting data 1 first. Only connect to database 2 to view the running results. It can be run twice and it can display the matching results after running, proving that the database switch is successful.
If you want to learn more related content, please visit the php Chinese website.
Recommended tutorial: thinkphp tutorial
The above is the detailed content of How to switch database in thinkphp323 model. For more information, please follow other related articles on the PHP Chinese website!