Answer the question
In order to leave comments, you need to log in
How to get database name in YII2?
I need to raise a migration to create a table.
The table will have a field that will be a foreign key to a field from another database.
I fixed database1.field
it and everything worked.
But I need dynamic.
From model i can get table name common\models\GoogleGroups::tableName();
but how to get database name from model?
Answer the question
In order to leave comments, you need to log in
private function getDsnAttribute($name, $dsn)
{
if (preg_match('/' . $name . '=([^;]*)/', $dsn, $match)) {
return $match[1];
} else {
return null;
}
}
$this->getDsnAttribute('dbname', $this->db->dsn);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question