Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if PDO is enabled in PHP?

Tags:

php

pdo

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.

like image 543
H. Ferrence Avatar asked May 24 '11 15:05

H. Ferrence


People also ask

How do I know if PDO is enabled in PHP?

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.

Is PDO included in PHP?

PDO is enabled by default as of php 5.1. 0 on most linux systems.

How do I know if PDO is installed on Ubuntu?

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.


2 Answers

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     ....... } 
like image 199
Salman von Abbas Avatar answered Nov 03 '22 23:11

Salman von Abbas


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.

like image 21
GolezTrol Avatar answered Nov 03 '22 22:11

GolezTrol