Defining MySQL connection in Slim Framework?

php, slim

Solution

You can define a function in your file (e.g. index.php)

    function getConnection() {
    $dbhost="yourdbhost";
    $dbuser="yourdbuser";
    $dbpass="yourdbpass";
    $dbname="yourdb";
    $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);  
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $dbh;
    }

Problem

I am hearing great things about Slim Framework- and it seems easy. Except none of the tutorials address where to put the MySQL info. I see things like `$dbCon = getConnection();` But where do I define the username/pw/db/host etc?

Original source