On Sunday, April 6, 2014 2:26:31 PM UTC-5, Herman Peeren wrote:
I have no problem connecting to multiple databases at all. That is not what I said.
Actually, you've said very little about the problem which is why I am asking if you can reproduce it.
This question simply asks if it's okay to use both PDO and MySQLi connections on the same database in the same application. (And the answers are "Why would you do that?")
Besides the problems that could occur in this way, you also use 2 database connections where 1 would be sufficient. When you have a high-traffic site, that is an unnecessary (and maybe even fatal) load.
Why would you use those two connections for one database at the same time? When you are making extensions for the Joomla CMS an want to use Doctrine in it (like I do). You need the mysqli-connection to run Joomla and I always used pdo (as everybody does) to run Doctrine.
Now Ihave not encountered problems with that the last years, and it was running on production sites, not just some tests. But as outlined above, there can be connection problems and unnecessary overload. I'm using the same database; sometimes even the same tables (for instance the users-table etc).
Definitely is going to cause more overhead -- doing the same thing twice does that.
But, other than memory and time needed to create a second DB instance, I'm still not sure what problems would result.
My solution was: to look at a pdo_mysql connection for Joomla. That is still my preferred solution, as I prefer pdo above mysqli (but that's a different discussion).
PDO is "better" in that it provides an approach to handles escaping -- but so does Joomla Query. (Probably less questions with the PHP community if Joomla adopted PDO but really they are both the same in terms of security.)
Fron this thread I learned that you can also use mysqli as connection in Doctrine. That avoids problems that could occur when mixing pdo and mysqli (I once read somewhare that some mysqli-commands don't work well if immediately issued after having used pdo to the same db).
OK - sounds like maybe you can head the mysqli way for Doctrine, too, and avoid duplicate connection resources.
But, it shouldn't create any problems (failures) to connect to the same database using Joomla Database package to the best of my knowledge. I have done this before, too, without any issue.
Yes, it's less performant since the work connecting to the database is done twice. Beyond the connection, however, it should be as fast to use two as one. It should work, too. But if there are problems, it'd be good to describe those in a reproducible way so that it can be fixed.