yii2 mysql如何跨数据库联表查询?
大家讲道理
大家讲道理 2017-04-17 15:41:34
0
3
809

wp_post在blog_cn数据库中,而stat_weibo在task数据库中。现在两个数据表需要进行连表查询,该如何实现?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
阿神

Also note that these two databases are in one mariadb instance. Cross-mariadb, cross-server join is not possible

小葫芦

Override the ActiveRecord::getDb() method and return to connect to the database according to the configured db component by default.

伊谢尔伦

You can do this if the two databases are in the same Mysql server

Override the tableName() method of the Weibo model class:

public static function tableName()
{
    preg_match("/dbname=([^;]+)/i", self::getDb()->dsn, $matches);
    return $matches[1].'.weibo';
}

If the two databases are not in the same Mysql server, there is no solution for the time being

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!