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 Using PHP with MySQL Connecting PHP to MySQL Getting Started with PDO

Jun XIE
Jun XIE
10,363 Points

can not connect to the database and shows access forbidden

In the video"getting started with PDO", I typed "<?php $db = new PDO("mysql:host=localhost;dbname=shirts4mike;port=3306","root",""); var_dump($db); ?> as it instructs. I opened the database.php file in the browser, but it shows "Access forbidden! You don't have permission to access the requested object. It is either read-protected or not readable by the server.". Then I checked in terminal that the port is 3306 and the password is blank, they are no problem. I also can access shirts4mike in terminal. I don't know if someone has met the same situation. If so, could you please help me with it? :P. Thanks in advance!

1 Answer

Philip Cox
Philip Cox
14,818 Points

Hi Jun. As Randy mentions, you may not need to add the port number, I didn't. Try some variations, drop the port number and just use the user name and password, root, root. Also, you have MAMP or WAMP running I take it?

Jun XIE
Jun XIE
10,363 Points

Dear Cox, thanks for your help, ^_^. I am using XAMPP. I downloaded the code into htdocs directly as I didn't have my own codes. Just now I found the code file in terminal has different prefix than others. It is not "drwxr-xr-x". I tried to change the authority granted to me to "drwxr-xr-x". It works fine now.