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

Databases

Working with MAMP.

MAMP seems to force me to place my databases in the Applications path. (Applications/MAMP/...) My localhost root is in username/Sites. I am trying to trying to build a website that uses PHP to connect to mySQL. But I cannot establish the connection. Here is the PHP.

<?php
    // 1. Create a database connection
    $dbhost = "localhost";
    $dbuser = "adminWidgetCorp";
    $dbpass = "adminUser01";
    $dbname = "widgetCorp";
    $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
    // Test if connection succeeded
    if(mysqli_connect_errno()) {
        die("Database connection failed: " .
             mysqli_connect_error() .
             " (" . mysqli_connect_errno() . ")"
        );
    }
?>

Is my inability to connect because my db is not in my localhost root but is down the Applications path? If so can I use MAMP to redirect the creation of my db to my localhost root, and how do I do that? This is my first attempt at doing this and I am building a site for someone who is paying me, so I need to get this down. Thanks.

The code sample looks like phony data because I am doing a proof of concept before I plug it into my website.