Skip to content

Instantly share code, notes, and snippets.

@sabadow
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sabadow/ca3e8c28250dbd005274 to your computer and use it in GitHub Desktop.
Save sabadow/ca3e8c28250dbd005274 to your computer and use it in GitHub Desktop.
Example for the #DevBurgos talk about Heroku
<?php
# function that reads DATABASE_URL env var and returns a connection
function pg_connection_string_from_database_url() {
extract(parse_url($_ENV["DATABASE_URL"]));
return "user=$user password=$pass host=$host dbname=" . substr($path, 1);
}
print "<h1>hello #DevBurgos</h1>";
# Establish the connection.
$pg_conn = pg_connect(pg_connection_string_from_database_url());
# silly query
$result = pg_query($pg_conn, "SELECT now()");
#print the result if has any
if (pg_num_rows($result)) {
print "\nObtained from DB:";
$row = pg_fetch_row($result);
print("- $row[0]");
}
?>
web: vendor/bin/heroku-php-nginx
@sabadow
Copy link
Author

sabadow commented May 7, 2014

Useful command heroku addons:add heroku-postgresql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment