title: Cross Database Relation doctrine 2 and php
body: <p>How can I implement this code in doctrine 2:</p>
  
  <pre><code> Doctrine_Manager::connection('mysql://root@localhost/doctrine_test1', 'doctrine_test1');
  Doctrine_Manager::connection('mysql://root@localhost/doctrine_test2', 'doctrine_test2');
  </code></pre>
  
  <p>any alternate. I am using this code for connection:</p>
  
  <pre><code>&lt;?php
  // bootstrap.php
  require_once "vendor/autoload.php";
  
  use Doctrine\ORM\Tools\Setup;
  use Doctrine\ORM\EntityManager;
  
  $paths = array("/path/to/entity-files");
  $isDevMode = false;
  
  // the connection configuration
  $dbParams = array(
      'driver'   =&gt; 'pdo_mysql',
      'user'     =&gt; 'root',
      'password' =&gt; '',
      'dbname'   =&gt; 'foo',
  );
  
  $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
  $entityManager = EntityManager::create($dbParams, $config);
  </code></pre>
  
  <p>example scenario:</p>
  
  <pre><code>--databse_a
  CREATE TABLE User (
      id INT AUTO_INCREMENT NOT NULL,
      address_id INT DEFAULT NULL,
      PRIMARY KEY(id)
  ) ENGINE = InnoDB;
  
  --databse_b
  CREATE TABLE Address (
      id INT AUTO_INCREMENT NOT NULL,
      PRIMARY KEY(id)
  ) ENGINE = InnoDB;
  
  ALTER TABLE database_a.User ADD FOREIGN KEY (address_id) REFERENCES database_b.Address(id);
  </code></pre>
  
  <p>Generate Entities and then try to fech results. You will get errors.</p>
  
  <p><strong>error in log</strong>: The target-entity Address cannot be found in 'User#address_id'. </p>