Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

saranyamoellers
saranyamoellers
31,692 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
31,692 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
31,692 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
31,692 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.