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

Shon Levi
Shon Levi
6,036 Points

Trying to make mysql connect and get an error

Hey you there, when I tried to make a database with sqlite it works fine, but when I tried to change it to mysql it brings me that error:

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/treehouse/workspace/index.php:6 Stack trace: #0 /home/treehouse/workspace/index.php(6): PDO->__construct('mysql:./databas...') #1 {main} thrown in /home/treehouse/workspace/index.php on line 6

Please explain me what why it brings that error, And what is the differences between the PDO drivers (sqlite, mysql, etc...)

Thanks, Shon :)

1 Answer

Hey Shon,

Can you paste in the connection code? Please replace sensitive passwords/usernames with safe content :-)

PDO is a wrapper for database connection and interaction. It would be annoying to have 6 different PDO type objects that all use different syntax/methods of connecting to each database type. So instead, PDO has different 'adaptors', which standardises how we talk to all these database types into one interface you can use in your code. You can find out more here: PHP PDO