简体   繁体   English

PDO:动态检测数据库驱动程序

[英]PDO: Dynamically detect database drivers

I'm creating my own CMS, part of this is making sure it is interoperable with different database types. 我正在创建自己的CMS,其中一部分是确保它可与不同的数据库类型互操作。 PDO is therefore my default choice, my question is: 因此,PDO是我的默认选择,我的问题是:

Is there any way to dynamically detect and set the database type in a PDO connection class? 有什么方法可以动态检测和设置PDO连接类中的数据库类型?

As far as i can see there isn't so i was thinking just doing a bunch of try/catch on different database types then writing the one that doesn't throw an exception to a config file. 据我所知没有,所以我在考虑对不同的数据库类型进行大量的try / catch,然后编写不会对配置文件引发异常的数据库。

Although PHP has extension_loaded() function, as it was noted in the comments, multiple databases support is not that easy. 正如注释中指出的那样,尽管PHP具有extension_loaded()函数,但对多个数据库的支持并不是那么容易。

Your question is a typical example of premature engineering. 您的问题是过早工程的典型示例。 You don't have your CMS yet, you don't have support for even one database, but your only concern is how to detect it. 您还没有CMS,甚至没有一个数据库的支持,但是您唯一关心的就是如何检测它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM