Pdo ( Portable Data Object ) needs to be installed if it is not done before. For windows platform go to control panel > Add remove program ( or Programs and features ) > Select your PHP installation and click Change. If you are installing PHP fresh then in the setup wizard you can select PDO from Extensions link.
PHP Data Object PDO installation or enable and creating connection string to manage MySQL database
Based on the database type you can enable or disable PDO drivers. Note that once you have done this process then automatically php.ini file gets edited and you may have to reboot your system. Note that PDO drivers are in your extension directory and in php.ini file this it to be enabled.
extension=php_pdo.dll
But in PHP 5.3 and above these dll are not required.
After installing pdo you can check your phpinfo function and ensure that PDO support is enabled.
Remove the semicolon (;) at the beginning to uncomment the line, then save the file. After making this change, restart your web server (e.g., Apache or Nginx) for the changes to take effect.
This ensures that the PDO MySQL extension is loaded and ready to be used in PHP for database interactions.
Checking PDO Installation
You can get all the PDO drivers installed in your system by using getAvailableDrivers() function. We will get an array with a list of drivers installed. Here is the code.
print_r(PDO::getAvailableDrivers());
We can check by using in_array function about any particular driver installed or not.
if(in_array("mysql",PDO::getAvailableDrivers())){
echo " You have PDO for MySQL driver installed ";
}else{
echo "PDO driver for MySQL is not installed in your system";
}
Example : Checking Enabled PDO Drivers
To see which PDO drivers are installed, use the following script: