-
-
Save sabadow/ca3e8c28250dbd005274 to your computer and use it in GitHub Desktop.
Example for the #DevBurgos talk about Heroku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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]"); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: vendor/bin/heroku-php-nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful command
heroku addons:add heroku-postgresql