Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do to use different connections in Doctrine?
    primarykey
    data
    text
    <p>I tried to use several transactions in Doctrine (v1.2.2). Here my test:</p> <pre><code>// Open a new database connection $cnx1 = Doctrine_Manager::connection('mydsn'); // $cnx1 will be named '0' // Open a second database connection $cnx2 = Doctrine_Manager::connection('mydsn'); // $cnx2 will be named '1' // Start a transaction on connection #1 $cnx1-&gt;beginTransaction(); // Update the name of user #1 $query1 = $cnx1-&gt;createQuery(); $query1-&gt;update('SfGuardUser')-&gt;set("username", "'Name 1'")-&gt;where("id='1'"); $query1-&gt;execute(); // Start an other transaction on connection #2 $cnx2-&gt;beginTransaction(); // Update the name of user #2 $query2 = $cnx2-&gt;createQuery(); $query2-&gt;update('SfGuardUser')-&gt;set("username", "'Name 2'")-&gt;where("id='2'"); $query2-&gt;execute(); // Commit transaction #2 $cnx2-&gt;commit(); </code></pre> <p>(The default isolation level is REPEATABLE READ.)</p> <p>After running the code, both user names have changed in the database. According to me, only the name of user #2 should be modified, as the transaction #1 has not yet been committed.</p> <p>When debugging, I saw that it is always the connection #2 (the last opened) which is used for all queries. Why ? </p> <p>In the Doctrine documentation, we can read "From the start Doctrine has been designed to work with multiple connections. Unless separately specified Doctrine always uses the current connection for executing the queries."</p> <p>How to do to use different connections and uniques transactions?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload