Connection management - Connection-component binding.php 820 Bytes
Newer Older
1

hansbrix's avatar
hansbrix committed
2 3 4 5 6 7
Doctrine allows you to bind connections to components (= your ActiveRecord classes). This means everytime a component issues a query
or data is being fetched from the table the component is pointing at Doctrine will use the bound connection.

 

<code type="php">
zYne's avatar
zYne committed
8
$conn = $manager->openConnection(new PDO('dsn','username','password'), 'connection 1');
hansbrix's avatar
hansbrix committed
9

zYne's avatar
zYne committed
10
$conn2 = $manager->openConnection(new PDO('dsn2','username2','password2'), 'connection 2');
hansbrix's avatar
hansbrix committed
11

zYne's avatar
zYne committed
12
$manager->bindComponent('User', 'connection 1');
hansbrix's avatar
hansbrix committed
13

zYne's avatar
zYne committed
14
$manager->bindComponent('Group', 'connection 2');
hansbrix's avatar
hansbrix committed
15

zYne's avatar
zYne committed
16
$q = new Doctrine_Query();
hansbrix's avatar
hansbrix committed
17 18

// Doctrine uses 'connection 1' for fetching here
zYne's avatar
zYne committed
19
$users = $q->from('User u')->where('u.id IN (1,2,3)')->execute();
hansbrix's avatar
hansbrix committed
20 21

// Doctrine uses 'connection 2' for fetching here
zYne's avatar
zYne committed
22
$groups = $q->from('Group g')->where('g.id IN (1,2,3)')->execute();
zYne's avatar
zYne committed
23
</code>
24