Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
We're going to use the Slim Skeleton to set up our application. Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
In the lifecycle of an application, there are multiple environments such as Development, Testing and Production. Each environment may have its own unique sources and credentials that need to be managed and secured. Environment variables are accessible to any programming language, and allow applications to adapt to their environment while keeping credentials secure.
Database
PDO Connection
$container['db'] = function($c) {
$db = $c->get('settings')['db'];
$pdo = new PDO($db['dsn'].':'.$db['database']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
};
You can download the database here. Or if you prefer, you can set up the database yourself. If you want to create the tables, you can use the following SQL commands:
CREATE TABLE "courses" (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`title` TEXT NOT NULL,
`url` TEXT NOT NULL )
CREATE TABLE "reviews" (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`course_id` INTEGER NOT NULL,
`rating` INTEGER NOT NULL,
`comment` BLOB NOT NULL )
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up