Development Tools Using PHP with MySQL Connecting PHP to MySQL Getting Started with PDO

saranyamoellers
saranyamoellers
26,779 Points

Fatal error: Class 'PDO' not found in... I can't connect to database?

<?php 
$db = new PDO("mysql:host=127.0.0.1;dbname=shirts4mike;port=3306","root","password");

var_dump($db);

2 Answers

Maybe you need to enable the PDO in you php.ini file? uncomment to enable.

saranyamoellers
saranyamoellers
26,779 Points

Hello, I found php.ini but I'm not sure where to enable it? I didn't see any comment symbol. I did clt+f to look for PDO in php.ini file, and I found a bunch of them. I don't know what to do and I didn't see any comment symbol to uncomment it. Thank you.

Depends on your server version, find these statements

extension=pdo.so

extension=pdo_mysql.so

OR

extension=pdo.dll

extension=pdo_mysql.dll

and remove the // to uncomment / activate them

Then restart your apache server (xampp or wamp)

saranyamoellers
saranyamoellers
26,779 Points

I found them , but none of them has any comment. They have ; (semicolon ) in front of them. ;extension=php_pdo.dll

yes, delete the semicolon

saranyamoellers
saranyamoellers
26,779 Points

We did it, it works! Thank you so much Haunguyen.

No problem. Now you know where to go to add/activate/inactivate server modules for php server.