2

I'm writing an application which makes use of some legacy code. The newer code uses PDO, while the older uses the original mysql library.

A large amount of data is input in a transaction in the first code, so that I can roll back on error, but the legacy code is called at some points and needs to see the same data; unless the connection is shared, the legacy code can't see the changes made by the newer code.

Somewhere down there PDO must have a connection handle for the database; is there any way to get at it? Is there another way to coerce the old mysql library calls to use the PDO connection? Is there anyway to open the old style connection, then tell PDO to use that connection? Any other ideas?

El Yobo
  • 14,823
  • 5
  • 60
  • 78

1 Answers1

1

I don't think what you want is possible : I've never seen that done, as each library (PDO, mysql, and mysqli) uses its own connection to the Dabatase -- which means, as you notices, that connections established using one of those are not shared with the others.

I suppose you'll have to find a way to migrate all of your code in one shot -- at least, for portions that need to work on the same transactions.

Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
  • Sad, but true. Next step - bringing all that crap old code up to date. *sigh* – El Yobo Dec 11 '09 at 01:41
  • 1
    As an addendum to this, I ended up writing a wrapper around the required MySQL functions so that they actually used the PDO functions underneath; we're still migrating all the old MySQL code, but this allows us to roll ahead in the mean time anyway. – El Yobo Jun 06 '10 at 10:42
  • @ElYobo I know this is way old, but any chance you could provide code/description of how you built this wrapper? – Michael Hommé Nov 17 '15 at 23:13
  • This was for a former employer, so I no longer have access to the code sorry. The idea is pretty straightforward though, just write your own mysql_query function (for example) that internally accesses a PDO object and passes on the call to that instead. – El Yobo Nov 18 '15 at 02:54