title: php PDO lock tables
body: <p>In this script I have:</p>
  
  <pre><code>$db = new PDO('mysql:host=localhost; dbname=name; charset=utf8', 'user', 'pass');
  $db -&gt; exec('LOCK TABLES `table1`, `table2` WRITE');
  // Do some stuff here
  $db -&gt; exec('UNLOCK TABLES');
  </code></pre>
  
  <p>The problem is that the tables don't seem to be locked. Multiple instances of the script are executed at the same time. The</p>
  
  <pre><code>// Do something here
  </code></pre>
  
  <p>code still fails to do stuff atomically as would be expected with the LOCK TABLES statement.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Also I have noticed that although I don't explicitly lock other tables that I use (for example <code>table3</code>) I can still read/write to them. That should not be possible according to the mySQL manual.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The <code>// Do some stuff here</code> code instantiates a few classes that do the DB work but which share the same <code>$db</code> PDO connection.</p>
  
  <p>This should not be the cause of the problem as I understand it, exactly because they share the same connection. The lock tables statement should be 'inherited' by them.</p>