Home >Backend Development >PHP Tutorial >Code for Yii framework to connect to mongodb database_php example
The yii2 framework is an upgraded version of yii. In this article, we explain how to connect to the database mongodb in the yii framework.
Add the following code to the folder common/config/main_local.php:
<?php return [ 'components' => [ 'mongodb' => [ 'class' => 'yii\mongodb\Connection', 'dsn' => 'mongodb://localhost:27017/数据库名' ], ], ];
The above is the code for connecting the Yii framework to the mongodb database introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank you all for your support of the Script House website!