How to make an INNER JOIN with two tables in different banks?

1

I have two different banks that I make the connection in the following way:

date_default_timezone_set('America/Sao_Paulo');
abstract class BancoDados
{
const host = 'localhost';
const novoweb = 'novoweb';
const WebAccount = 'Web_Account';
const Member = 'Member';
const user = 'usuario';
const password = 'senha';
static function conectarW()
{
    try 
    {
        $pdoW = new PDO("mysql:host=".self::host.";dbname=".self::novoweb.";charset=utf8", self::user, self::password);
        $pdoW->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        return $pdoW;
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
}
static function conectarWA()
{
    try 
    {
        $pdoWA = new PDO("mysql:host=".self::host.";dbname=".self::WebAccount.";charset=utf8", self::user, self::password);
        $pdoWA->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        return $pdoWA;
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
}
}

I have two values in the novoweb database in the shopweb table with the id and nome columns, where id I enter the Web_Account database in the GameTail table in the ItemIdx column but I do not know how do INNER JOIN because I make the query like this.

static function historicoshopweb($pdoWA,$id,$admin)
{
    try {
        if ($admin == 1) {
            $historico = $pdoWA->prepare("SELECT * FROM GameTail  ORDER BY RegDate DESC");
            $historico->execute();
        } else {
            $historico = $pdoWA->prepare("SELECT * FROM GameTail WHERE IdIdx = :id ORDER BY RegDate DESC");
            $historico->bindValue(":id",$id);
            $historico->execute();
        }
            $historicos = $historico->fetchAll(PDO::FETCH_OBJ);

            return $historicos;

    } catch (PDOException $e) {
        echo "ERROR: ".$e->getMessage();
    }
}

Then I want instead of the ItemIdx to appear the name of the item.

    
asked by anonymous 15.12.2017 / 17:27

1 answer

1

From what I've noticed, both banks are on the same server and are accessed by the same user. So, try to make the connection without passing the database name and join it like this:

SELECT g1.*, g2.* FROM WebAccount.GameTail g1 left join novoweb.GameTail g2 on g2.IdIdx = g1.IdIdx ORDER BY g1.RegDate DESC
    
15.12.2017 / 17:34