How to Determine If Pdo Is Enabled in PHP

How to determine if PDO is enabled in PHP?

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.

How can I tell if PDO module installed/disabled?

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.

php code to test pdo is available?

Aside from using phpinfo() to see if it's correctly listed

if (!defined('PDO::ATTR_DRIVER_NAME')) {
echo 'PDO unavailable';
}

How to check if PDO support is enabled in my Apache Installation?

The configure command in your PHP output shows:

'--disable-pdo'

so I think it's safe to assume that they haven't enabled it.

PDO not found error even tho it is installed and enabled in php.ini

Pdo works if i don't use namespaces

This is the key to your solution. PDO is a class in PHP. All class names should be fully qualified, otherwise PHP will look for that class' definition only in the current namespace. To use PDO in any other namespace than global you would need to specify the global namespace with the help of a single \

$this->pdo = new \PDO('mysql:host=127.0.0.1;dbname=db', 'user', 'password');

Side note. The way you are creating the PDO instance is not the recommended one. You should specify the charset as well as enable PDO error reporting.

$this->pdo = new \PDO('mysql:host=127.0.0.1;dbname=db;charset=utf8mb4', 'user', 'password', [
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_EMULATE_PREPARES => false,
]);

Never catch exceptions, just to die/exit. Either let the exceptions bubble up, or handle them properly. Displaying the error message to the user manually is a potential security issue.

Cant Enable PDO features from whm panel

Run phpinfo() in a quick script and double check if PDO is in fact enabled.

If you have ssh access to your web-server or an option to directly edit the php.ini file in some manner add the following:

extension="pdo.so"
extension="pdo_mysql.so"

If you don't have that capability with your hosting provider, you may need to contact them and ask for the extensions to be added on their side.

PDO installation - enable pdo_mysql

after a day of research, I found my problem!
this may be useful for new developers:
it works for me using Appserv 2.5.10 on Windows 8:

  1. first make sure that you edit the right php.ini file. Do that by going to view the phpinfo(), search for Configuration File (php.ini) Path in the info page, you will find the directory that you need to configure the file in
  2. after Editing the php.ini file, save the changes and restart your device

at first i didn't now how to restart the Apache, i thought it might be a cmd command or clicking a patch file. but it raises errors for me when i used apache_start.bat patch. restarting the PC will do fine!

PDO extension not loading in PHP

I found the error :
First i started using php in direct command line, and set the env' variable LD_DEBUG=libs:

./php -c /path/to/php.ini /path/to/php/file.php

So with that i was able to get the debug on the dynamic loading of my modules and on the php.ini.

I saw that there was an uncommented line that was blocking the loading of the modules in the INI file, then you have to load the mysql.so module before the pdo_mysql.so and of course restart you apache server.



Related Topics



Leave a reply



Submit