Yii Framework Forum: Switching databases between development and deployment - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Switching databases between development and deployment [solved] Rate Topic: -----

#1 User is offline   tklustig 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 225
  • Joined: 20-April 17
  • Location:Hannover

Posted 31 July 2017 - 07:25 AM

Hy guys,
how to switch probably databases from development to deployment in yii2-advanced!
I use following config-file:
.
.
.
     'db_developpment' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=yii2_widget',
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
        ],
        'db_deployment' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host="http:/tklustig.ddns.net";dbname=yii2_widget',
            'username' => 'my_name',
            'password' => 'my_password',
            'charset' => 'utf8',
        ],
.
.
.

I suppose, it's necessary to code an IF-statement in order to difference between developpment and deployment settings.
How to code this IF-statement correctly?
0

#2 User is offline   Patrick Jones 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 495
  • Joined: 14-July 12
  • Location:Berlin

Posted 31 July 2017 - 08:36 AM

That's what environments are for in the advanced template.

https://github.com/y...environments.md
Freelance developer for hire - send me a message!
1

#3 User is offline   tklustig 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 225
  • Joined: 20-April 17
  • Location:Hannover

Posted 31 July 2017 - 08:58 AM

Quote

I suppose, it's necessary to code an IF-statement in order to difference between developpment and deployment settings.
How to code this IF-statement correctly?


As it seems, I found solution by myself. Is it probably or just functionally?
<?php
if(YII_ENV=='prod'){
return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=http://tklustig.ddns.net;dbname=yii2_widget',
            'username' => 'my_name',
            'password' => 'my_password',
            'charset' => 'utf8',
        ],
   
    ],
];
}else{
return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=yii2_widget',
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
        ],
   
    ],
];
}
?>

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users