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 trialsebastian rojas
571 PointsCan't connect to database - mysql
Hey!
I am following this video http://teamtreehouse.com/library/using-php-with-mysql/connecting-php-to-mysql/getting-started-with-pdo-2
and i can't connect to the database! I have checked so my code is right and such but it won't work at all!
Anyone can help me with this?
Kind regards, Sebastian
6 Answers
Ivan Aguilar
8,286 PointsTry removing the last parameter (password). XAMMP has the username of root, but no password.
David Rynn
10,554 PointsRemoving the last parameter, the password ('root') worked for me too. Thanks.
sebastian rojas
571 Points<?php
$db = new PDO("mysql:host=localhost;dbname=sweaters4simba;port=8889", "root", "root");
var_dump($db);
Andrew McCormick
17,730 Pointshave you tried without the port? most of the time (at least in my experience) you don't need to specify the post.
sebastian rojas
571 PointsAh, no i havent! but now i have some big problems with xampp haha..
Andrew McCormick
17,730 Pointswell that will do it too :/
sebastian rojas
571 PointsSo i removed the port
<?php
$db = new PDO("mysql:host=localhost;dbname=sweaters4simba;", "root", "root");
var_dump($db);
?>
and got this error
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)' in C:\xampp\htdocs\database.php:3 Stack trace: #0 C:\xampp\htdocs\database.php(3): PDO->__construct('mysql:host=loca...', 'root', 'root') #1 {main} thrown in C:\xampp\htdocs\database.php on line 3
trying to understand the problem but don't :(
sebastian rojas
571 PointsI think i have solved it now!
Atiba Lashley
5,724 PointsI'm havin the same problem....when try to load it I get this message:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)' in C:\xampp\htdocs\database.php:3 Stack trace: #0 C:\xampp\htdocs\database.php(3): PDO->__construct('mysql:host=loca...', 'root', 'root') #1 {main} thrown in C:\xampp\htdocs\database.php on line 3
Atiba Lashley
5,724 Points<?php
$db = new PDO("mysql:host=localhost;dbname=shirts4mike;port=3306","root","root");
var_dump($db);
?>
My Code
Muhammad Atif
117 PointsI was having the same issue .Removing the last parameter(password) worked for me .Thanks Ivan
Andrew McCormick
17,730 PointsAndrew McCormick
17,730 Pointsplease post your code that you have so far. thanks.