Home  >  Article  >  Backend Development  >  Code for Yii framework to connect to mongodb database_php example

Code for Yii framework to connect to mongodb database_php example

WBOY
WBOYOriginal
2016-08-17 13:02:41991browse

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:

<&#63;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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn