6

I'm developing a PHP application. I just moved a bunch of files over to the production server, to discover that PDO is apparently not installed (Fatal error: Class 'PDO' not found in [file] on line [line]). The prod server is using PHP 5.3.6; according to the documentation I've found, "PDO and the PDO_SQLITE driver is enabled by default as of PHP 5.1.0".

I have very little experience administering PHP. How do I tell if this module is installed but disabled, or absent altogether? And what do I need to do to get it running?

BlairHippo
  • 9,502
  • 10
  • 54
  • 78
  • Can we see your code in case its just a typo? How are you creating the PDO connection? – Ozzy Apr 30 '12 at 18:44
  • @Ozzy -- It works on my local dev server, so I'm pretty confident it's not a typo. – BlairHippo Apr 30 '12 at 18:47
  • You probably need to edit the php.ini file, look for `extension=php_pdo.dll` – Ozzy Apr 30 '12 at 18:50
  • @Ozzy: The string "pdo" does not occur in the php.ini files on that server (/usr/local/lib/php.ini, /user/lib/php.ini, /etc/php.ini -- I have no idea which one I care about). – BlairHippo Apr 30 '12 at 18:58
  • Possible duplicate of [How to determine if PDO is enabled in PHP?](http://stackoverflow.com/questions/6113262/how-to-determine-if-pdo-is-enabled-in-php) – Dov Benyomin Sohacheski May 03 '16 at 02:59

2 Answers2

29

Generally you can just do phpinfo(); to find out what modules are installed.

Or from the commandline:

php -m

Additionally you could use: class_exists('PDO') to find out whether the PDO class indeed is accessible.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
  • php -m does not show PDO, pdo_mysql, or pdo_sqlite, all of which are present in my dev box. Where should I look to get those running? Should I assume they're present but disabled, or should I assume I'll have to install them from scratch? – BlairHippo Apr 30 '12 at 18:48
  • @BlairHippo What do you use to run your script? – Leri Apr 30 '12 at 18:51
  • @BlairHippo It depends. You may be able to activate it in your `php.ini` file. Or you might have to recompile php with pdo and the driver you want to use. – PeeHaa Apr 30 '12 at 18:52
  • @RepWhoringPeeHaa: The string "pdo" does not occur in any of the php.ini files on the server (/usr/local/lib/php.ini, /usr/lib/php.ini, /etc/php.ini -- I have no idea which one I care about). You may be right about needing to recompile PHP. Unfortunately, the host provider doesn't provide sysadmin support, and nobody in the company is qualified to do it, so I have absolutely no confidence I can recompile PHP without breaking something. I think I need to curl up under my desk and weep quietly for a while.... – BlairHippo Apr 30 '12 at 18:56
  • @PLB: Not sure I understand the question; it's running under Apache. – BlairHippo Apr 30 '12 at 18:58
  • @PLB: Fedora 8 (really), Apache 2.0.63. – BlairHippo Apr 30 '12 at 19:00
  • @BlairHippo there must be `extension=pdo.so` line in your php.ini – Leri Apr 30 '12 at 19:03
  • @PLB: "cat /etc/php.ini | grep pdo", "cat /usr/lib/php.ini | grep pdo", and "cat /usr/local/lib/php.ini | grep pdo" all return nothing. – BlairHippo Apr 30 '12 at 19:06
  • @BlairHippo re-installation is the onliest thing I can advise. It seems that PDO is not installed. – Leri Apr 30 '12 at 19:09
0

In the terminal type:

php -i |grep PDO

The -i is used to display the output of phpinfo().

The |grep will filter the list to the ones containing PDO.

Szekelygobe
  • 2,309
  • 1
  • 19
  • 25