Skip to content

Instantly share code, notes, and snippets.

@andyvanee
Created February 6, 2015 17:07
Show Gist options
  • Save andyvanee/fe5374a0e3d60bd40853 to your computer and use it in GitHub Desktop.
Save andyvanee/fe5374a0e3d60bd40853 to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
Dotenv::load($_SERVER['DOCUMENT_ROOT'].'/../');
Dotenv::required(array(
'MYSQL_HOSTNAME',
'MYSQL_USERNAME',
'MYSQL_DATABASE',
));
$server = getenv('MYSQL_HOSTNAME');
$username = getenv('MYSQL_USERNAME');
$password = getenv('MYSQL_PASSWORD');
$database = getenv('MYSQL_DATABASE');
try {
$dbh = new PDO("mysql:host=$server;dbname=$database", $username, $password);
foreach($dbh->query('SELECT * from sample') as $row) {
print_r($row);
}
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment