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 trialAmit Kumar
1,063 Pointshow to connect mysql on local environment
$db = new PDO("mysql:host=localhost;dbname=database.bd;port=3306","root","mypass");
2 Answers
Boloni Hustle
86 PointsIf you're using MAMP the default password and username are both root and also you don't have to type the file type on the dbname part. So for me the following statement worked well
$db = new PDO("mysql:host=localhost;dbname=database;port=3306","root","root");
Also before doing all that you should've imported your database into mysql
jlampstack
23,932 PointsYour connection looks correct except there is a typo in your dbname. Try changing database.bd to database.db.
Make sure that your are connected to your local Server (Such as XAMPP or WAMP etc.), that the server is running and that the database exists on the server otherwise there is nothing to connect to and it will fail.