Answer the question
In order to leave comments, you need to log in
Yii2 how to query related tables of different databases on different servers?
Hello. The essence of the question is this: there are 2 databases, they are located on different servers, they are connected using different users \passwords. For GridView it is necessary to make sorting of a column which is selected from a remote database. Sampling through a separate request to a remote database for each element works fine. But for sorting, as I understand it, it is necessary to do a join, and this is where an error occurs. Tell me, is it possible to sort in a query with 2 databases located on different servers?
Error: "SELECT command denied to user 'user'@'localhost' for table 'game'"
// Код, который выбирает игры и связные данные
$query = Game::find()
->with(['relations', 'user', 'categories', 'characters'])
->joinWith('core as core');
$config = [
'query' => $query,
'sort' => $this->getSort(),
'pagination' => ['pageSize' => 40]
];
$dataProvider = new ActiveDataProvider($config);
// метод для сортировки данных
// ошибка в колонке complaints
private function getSort()
{
return new Sort([
'attributes' => [
'id',
'name',
'complaints' => [
'asc' => ['core.complaints' => SORT_ASC],
'desc' => ['core.complaints' => SORT_DESC],
]
],
]);
}
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'подключение',
'username' => 'юзер',
'password' => 'пароль',
'charset' => 'utf8',
],
'db_core' => [
'class' => 'yii\db\Connection',
'dsn' => 'подключение',
'username' => 'юзер',
'password' => 'пароль',
'charset' => 'utf8',
],
Answer the question
In order to leave comments, you need to log in
it will not be possible to join between two bases, as an option I see such a perversion:
they made a request to 1 base, took the data, formed a clone in the second base, then we work within the same base.
Or implement filtering already in php, where there are two data arrays.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question