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


Connecting Shirts4Mike PHP Website to MySQL using XAMPP

I've completed the PHP track up to the section where the shirts4mike website needs to directly access the mysql database. i successfully created the database using XAMPP mysql platform but somewhere there's a disconnect between the test php file (database.php) and allowing that php file to access the database.

this is the error exactly as it appears when i load the database.php:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. ' in C:\xampp\htdocs\database.php:15 Stack trace: #0 C:\xampp\htdocs\database.php(15): PDO->__construct('mysql:host=loca...', 'root', 'root') #1 {main} thrown in C:\xampp\htdocs\database.php on line 15

Hello! Can you post database.php? It sounds like you're using the wrong hostname or port but we need a little more info to find out ;)

1 Answer

ports etc were all correct. below is my solution.

yes i could load the database.php page... i found the problem was that the passwd was set to nothing on XAMPP but it wouldn't accept it if i didn't put a blank " " place for where the passwd would go in the database.php file. I had tried resetting the passwd in XAMPP's mysql admin page and then used that new passwd in the database.php file but that didn't work either.

i'm currently operational with database.php able to access the database with this code: $db = new PDO("mysql:host=localhost;dbname=shirts4mike;port=3306","root",""); var_dump($db);

not a perfect solution but it should allow me to do the lessons.

oh btw this was using windows 7 pro 64bit if that helps.