Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FBUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function login($redirect) {
$authorize_url = "https://www.facebook.com/dialog/oauth?client_id=$app_id" .
"&redirect_uri=$home&state=" . $state . "&scope=$scope";
// Now we redirect the user to the login page
echo("<script> top.location.href='" . $authorize_url . "'</script>");
echo("<script> window.location.href='" . $authorize_url . "'</script>");
return false;
// Once we have that code, we can now request an access-token. We check to
// ensure that the state has remained the same.
Expand Down
28 changes: 28 additions & 0 deletions db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
# This function reads your DATABASE_URL config var and returns a connection
# string suitable for pg_connect. Put this in your app.
function pg_connection_string_from_database_url() {
extract(parse_url($_ENV["DATABASE_URL"]));
return "user=$user password=$pass host=$host dbname=" . substr($path, 1); # <- you may want to add sslmode=require there too
}

# Here we establish the connection. Yes, that's all.
$pg_conn = pg_connect(pg_connection_string_from_database_url());
if(!pg_conn)
{
echo("You have not added database yet from terminal issue following command");
echo("<code>heroku addons:add shared-database</code>");
}

# Now let's use the connection for something silly just to prove it works:
$result = pg_query($pg_conn, "SELECT relname FROM pg_stat_user_tables WHERE schemaname='public'");

print "<pre>\n";
if (!pg_num_rows($result)) {
print("Your connection is working, but your database is empty.\nFret not. This is expected for new apps.\n");
} else {
print "Tables in your database:\n";
while ($row = pg_fetch_row($result)) { print("- $row[0]\n"); }
}
print "\n";
?>