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

Sai Kiran Dasika
PLUS
Sai Kiran Dasika
Courses Plus Student 7,278 Points

Driver Error while using PDO on workspaces

Hey guys, I was getting a " could not find driver" error when ever I try to connect to a mysql database through PDO from the workspaces. Does anyone know what must be the problem with the PHP configuration ?

Benjamin Payne
Benjamin Payne
8,142 Points

Hey Sai, Can you copy and paste your code into here?

Sai Kiran Dasika
Sai Kiran Dasika
Courses Plus Student 7,278 Points
try{
  $db = new PDO('mysql:host=hostname;dbname=databasename','username','password');
}
catch(Exception $e)
{
 echo $e->getMessage();
 die();
}

This was the code that I have it always says driver not found

Will you post the rest of your code as well? That code looks correct to me, so are you positive the error is coming from that? Also, I add a string to the echo $e->getMessage() line so it looks like this:

echo e->getMessage() . ' file function';

This makes sure I know where it really came from.

Benjamin Payne
Benjamin Payne
8,142 Points

Driver Not Found usually indicates you are trying to connect using a driver not available in the php.ini settings, but the fact that this is comming from Workspaces is very weird. Your code looks correct though...so I'm not sure what's going on.

Try adding that string to the end of the exception and also post the rest of your code here like Ted suggested. Adding the string won't fix anything but it will tell you for sure where the exception is comming from.

Best, Ben

Actually, posting a link to the fork snapshot would be best. It is the camera icon on the upper right side of the Workspace. Then open the link it creates and copy that or right click and copy the path. If you post that we can then go into your code and play with it directly to figure out the problem and post back to you what we find.