在PDO中的多个数据库之间切换 [英] Switch between multiple database in PDO
问题描述
我是PDO的新手.我想知道在PDO中是否有类似于mysql_select_db的东西,这样我可以在运行时在不同数据库之间切换,而无需创建新对象.
I'm new to PDO. I would like to know if there is anything similar to mysql_select_db in PDO, so that i can switch between different databases during runtime without the need for creating a new object.
推荐答案
没有,如果要在运行时同时使用两个PDO对象,则需要为单独的连接创建两个PDO对象.
There is not, you will need to create two PDO objects for the separate connections if you would like to use both at runtime.
下面@laz的有趣观点(我想这是我的回答遭到否定的原因).我当时在考虑数据库位于单独的服务器tbh上的假设,在这种情况下,我的回答是正确的.
Interesting point by @laz below (which I'm guessing is the cause of negative votes on my answer). I was thinking under the assumption that the databases were on separate servers tbh, in which case my answer stands.
这篇关于在PDO中的多个数据库之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!