将旧的mysql与PDO混合 [英] Mixing old mysql with PDO

查看:58
本文介绍了将旧的mysql与PDO混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用一些旧代码的应用程序.较新的代码使用PDO,而较旧的代码使用原始的mysql库.

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.

在那儿的某个地方,PDO必须具有数据库的连接句柄;有什么办法吗?有没有其他方法可以强制旧的mysql库调用使用PDO连接?无论如何,有没有打开旧式的连接,然后告诉PDO使用该连接?还有其他想法吗?

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?

推荐答案

我不认为您想要的是可能的:我从未见过这样做,因为每个库(PDO,mysql和mysqli)都使用自己的库与Dabatase的连接-如您所注意到的,这意味着使用其中一个建立的连接不会与其他连接共享.

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.

这篇关于将旧的mysql与PDO混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆