title: Using PHP PDO in an existing (legacy) application. Multiple SQL connections?
body: <p>I have been tasked to write a bunch of extensions to an existing legacy PHP app. The original app is... erm... quite bad. It's 125K lines of spaghetti code littered with raw SQL statements and using the <code>mysql_*</code> functions. Every day I find things that really belong on TheDailyWTF. My plan so far is to keep my new code as separate as possible from the legacy code. For database access, I plan to use <a href="http://j4mie.github.com/idiormandparis/" rel="nofollow">Idiorm and Paris</a>, two really nice little libraries built on top of PDO.</p>
  
  <p>But how will I handle database connections? Or how does PHP handle them internally? I worry that using PDO, every page call will open two separate connections to the database. One from the legact <code>mysql_connect()</code> call and one from PDO. Is that true, or will PHP simply share the same connection in the background? Is there any way to make PDO and the legacy <code>mysql_*</code> functions use the same database connection? Does it even matter at all it I opens two connections on every page load (note: the app is not using transactions)?</p>
  
  <p>I'm a little hesitant about going over those 125K lines of spaghetti code and replacing all the <code>mysql_*</code> functions with something else. I want to touch the original code as little as possible and not break my brain on it.</p>
  
  <p>Thanks in advance for any advice.</p>