1
0
mirror of synced 2024-12-14 15:16:04 +03:00
doctrine2/manual/docs/Connection management - Connection-component binding.php

25 lines
820 B
PHP
Raw Normal View History

2007-04-14 01:49:11 +04:00
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">
2007-05-07 19:44:20 +04:00
$conn = $manager->openConnection(new PDO('dsn','username','password'), 'connection 1');
2007-04-14 01:49:11 +04:00
2007-05-07 19:44:20 +04:00
$conn2 = $manager->openConnection(new PDO('dsn2','username2','password2'), 'connection 2');
2007-04-14 01:49:11 +04:00
2007-05-07 19:44:20 +04:00
$manager->bindComponent('User', 'connection 1');
2007-04-14 01:49:11 +04:00
2007-05-07 19:44:20 +04:00
$manager->bindComponent('Group', 'connection 2');
2007-04-14 01:49:11 +04:00
2007-05-07 19:44:20 +04:00
$q = new Doctrine_Query();
2007-04-14 01:49:11 +04:00
// Doctrine uses 'connection 1' for fetching here
2007-05-07 19:44:20 +04:00
$users = $q->from('User u')->where('u.id IN (1,2,3)')->execute();
2007-04-14 01:49:11 +04:00
// Doctrine uses 'connection 2' for fetching here
2007-05-07 19:44:20 +04:00
$groups = $q->from('Group g')->where('g.id IN (1,2,3)')->execute();
2007-05-07 19:47:02 +04:00
</code>