Is there a PHP command I can use to determine if PDO is enabled or disabled?
I know I an manually run phpinfo() and eyeball it, but I have a script I run various web servers that display selected PHP configuration settings for the server.
So I am looking to see if there is a command I can use.
if ( extension_loaded('pdo_<database type here>') ) { // e.g., pdo_mysql ....... } Show activity on this post. I appreciate the support and all the upvotes I still get, but please check Salman Abbas's answer for the proper way to do this. Was going to suggest defined() but PDO switched to class constants.
PDO is enabled by default as of php 5.1. 0 on most linux systems.
Generally you can just do phpinfo(); to find out what modules are installed. Additionally you could use: class_exists('PDO') to find out whether the PDO class indeed is accessible.
The proper way of determining that will be using the extension_loaded function:-
if ( extension_loaded('pdo') ) { ....... }
And you might also want to check for the database-specific PDO driver using:-
if ( extension_loaded('pdo_<database type here>') ) { // e.g., pdo_mysql ....... }
Check if the class exists:
if (class_exists('PDO'))
I appreciate the support and all the upvotes I still get, but please check Salman Abbas's answer for the proper way to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With