K
K
KevinSmash2019-11-13 21:22:25
MySQL
KevinSmash, 2019-11-13 21:22:25

Join tables from 2 db yii2?

There are 2 tables in 2 different mysql dbs. It is necessary to make join without using active record. How to do it? Here is a query that works in phpmyadmin:

select t1.AdId, t1.City from butuzLOCAL.product as t1 join statistic.user_2 as t2 on t1.AdId = t2.AdId
where t2.date = '2019-11-12'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Ninazu, 2019-11-13
@KevinSmash

$query = "SELECT 
            t1.AdId, 
            t1.City 
          FROM butuzLOCAL.product AS t1 
            JOIN statistic.user_2 AS t2 ON t1.AdId = t2.AdId
          WHERE t2.date = :dttm";

$results = Yii::$app->db
    ->createCommand($query)
    ->bindValues([
        'dttm'=>'2019-11-12'
    ])
    ->queryAll();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question