tklustig
(Kipp Thomas)
1
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?
patrickm
(Yiiframework)
2
That’s what environments are for in the advanced template.
tklustig
(Kipp Thomas)
3
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',
],
],
];
}
?>