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

Databases

Matthew Root
Matthew Root
5,392 Points

.php connection to database

Hey! I am attempting to connect to my hostgator (phpmyadmin) database. When I plug in run my PDO: try { $db = new PDO("mysql:host=localhost;dbname=$dbname;port=3306"$username","$password"); var_dump($db); } catch (PDOEXCEPTION $e){ echo $e->getMessage(); exit; }

This error is what I get in my browser when I punch in my connection.php: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user...

Any thoughts I what I am doing wrong? Thanks!

1 Answer

Kevin Korte
Kevin Korte
28,149 Points

I would double check the user permissions for that database. It would seem that either the user doesn't exist, or they don't have sufficient rights to access that database.