Are there any drawbacks to having multiple db connections?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Are there any drawbacks to having multiple db connections?

Post by thinsoldier »

I'm very slowly updating a legacy project to be php7 compliant.

There are many raw mysql_query calls, and functions that contain mysql_query, and primative poorly written models that use both.

I want to switch to either raw PDO or something like https://github.com/colshrapnel/safemysql or a stand-alone version of Laravel's Eloquent but I won't be able to update every part of the project all at once. This means most views will do both the original mysql_connect and the connection for the new library.

Are there any drawbacks or problems that arise from making 2 db connections in the same script?
Warning: I have no idea what I'm talking about.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Are there any drawbacks to having multiple db connection

Post by requinix »

Well, it will double the number of connections open to your database, meaning you'll exhaust that resource twice as fast. Some things like transactions and temporary tables don't work across connections.

Don't rush the upgrade. Do it as you can, test, and release when it's ready.
Post Reply