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 mysql_*
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 Idiorm and Paris, two really nice little libraries built on top of PDO.
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 mysql_connect()
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 mysql_*
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)?
I'm a little hesitant about going over those 125K lines of spaghetti code and replacing all the mysql_*
functions with something else. I want to touch the original code as little as possible and not break my brain on it.
Thanks in advance for any advice.