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

PHP PHP & Databases with PDO Getting Started With PDO Connecting with PDO

Hannah Carpenter
Hannah Carpenter
8,650 Points

Can't connect using PDO

I can't seem to connect to the database using the PDO method I have tried out various different suggestions, but can't seem to get it to work.

I am on a Mac using Mamp locally, but have using tried using my Siteground hosting also. I can connect normally to databases I create in both environments. I just don't get how to do the a PDO connection at all.

does MAMP allow sqlite ?

also I had to install some stuff on ubuntu before sqlite would work locally. used this https://superuser.com/questions/320894/how-to-install-the-sqlite-pdo-extension-on-ubuntu

you might have to do something similar on a mac

1 Answer

Dave StSomeWhere
Dave StSomeWhere
19,870 Points

Hi Hanna,

Have you run phpinfo() on your MAMP setup and do you see the PDO section?

I'm not on a MAC - did you see this Other MAMP Discussion

Hannah Carpenter
Hannah Carpenter
8,650 Points

Thanks for replying.

Yes I saw that discussion but didn't help me resolve the issue.

I can see the PDO section in phpinfo() it has 'pdo drivers: mysql, sqlite, pgsql'. Should there be anything else here?

I have been able to get a PDO connection to work on my hosting account, so it's just working out how to get in to work locally.

I can get a msqli connection to work, so I know the database info and the user permissions is good.