Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function retrieveConnection($file) {
- // takes a filename where heroku connection parameters are stored and returns a connection object
- $handle = fopen($file, "r") or die("Unable to open file!\r\n");
- $c_string = fread($handle, filesize($file));
- // the connection string from heroku is formatted as follows
- // username is between the first // and the first :
- // password is after the first : and before the first @
- // server is after the first @ and before the second :
- // port is after the second : and before the last /
- // database name is after the last /
- $p1 = strpos($c_string, "//");
- $p2 = strpos($c_string, ":", $p1);
- $p3 = strpos($c_string, "@", $p2);
- $p4 = strpos($c_string, ":", $p3);
- $p5 = strpos($c_string, "/", $p4);
- print "Connection string: \r\n" . $c_string . "\r\n";
- $username = substr($c_string, $p1 + 2, ($p2-$p1) - 2);
- $password = substr($c_string, $p2 + 1, ($p3-$p2) - 1);
- $server = substr($c_string, $p3 + 1, ($p4 - $p3) - 1);
- $port = substr($c_string, $p4 + 1, ($p5 - $p4) - 1);
- $database = substr($c_string, $p5 + 1);
- print "username: " . $username . "\r\n";
- print "password: " . $password . "\r\n";
- print "server: " . $server . "\r\n";
- print "port: " . $port . "\r\n";
- print "database: " . $database . "\r\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement