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 trialSamuel L. Moreira
9,587 Points500 Internal Server Error
Hey there. First time I'm using forum and as I didn't saw any post related to a similar problem... here's mine:
I'm starting "Using PHP with MySQL" track and right after the first lines of code I'm getting an 500 Internal Server Error and I can't get the object(PDO)#1 (0) {} message that Randy wants.
Basically... nope, not everything went correct. :P
I'm using WAMP therefore, I don't know if the proper code I should use is this one:
<?php
$db = new PDO("mysql:host=localhost;dbname=badbad","root"," ");
var_dump($db);
?>
I don't use password to enter my phpMyAdmin so, that's why I left password field in black. The path I'm using is something like:
localhost/htdocs/database.php
Thanks in advance for any tips around this and feel free to ask more information, cheers.
P.S.
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at admin@example.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log."
1 Answer
Andrew Shook
31,709 PointsTry removing the space between the quotation marks where your password is suppose to be in the new PDO declaration. Right now you are passing in a single space as the password when you want to be passing in nothing. So your PDO statement should look like this:
<?php
$db = new PDO("mysql:host=localhost;dbname=badbad", "root", "");
var_dump($db);
?>
Samuel L. Moreira
9,587 PointsSamuel L. Moreira
9,587 PointsThanks for your answer Andrew, the password field was indeed wrong with that space between quotation marks. However, that was not even the main error. The problem was on the index file with the "include" and "ROOT_PATH" statement. As my path was localhost/htdocs/database.php instead of localhost/database.php, I had to change the code in the index file. At last but not the least, the file .htaccess was also giving problems. Cheers.