将旧的 mysql 与 PDO 混合
我正在编写一个使用一些遗留代码的应用程序。较新的代码使用 PDO,而较旧的代码使用原始 mysql 库。
第一个代码中的事务中输入了大量数据,以便我可以在错误时回滚,但是在某些时候会调用遗留代码并需要查看相同的数据;除非连接是共享的,否则旧代码无法看到新代码所做的更改。
在下面的某个地方,PDO 必须有一个数据库的连接句柄;有什么办法可以得到它吗?是否有另一种方法可以强制旧的 mysql 库调用使用 PDO 连接?是否有办法打开旧式连接,然后告诉 PDO 使用该连接?还有其他想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为你想要的是可能的:我从来没有见过这样做,因为每个库(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.