Guest User

Untitled

a guest
Oct 29th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <?php
  2.  
  3. // connect to our mysql database server
  4.  
  5. function getDatabaseConnection() {
  6. if (strpos($_SERVER['SERVER_NAME'], "c9users") !== false) {
  7. // running on cloud9
  8. $host = "localhost";
  9. $username = "root";
  10. $password = "cst336"; // best practice: define this in a separte file
  11. $dbname = "memes_v2";
  12. } else {
  13. // running on Heroku
  14. $host = "";
  15. $username = "";
  16. $password = "";
  17. $dbname = "";
  18. }
  19.  
  20.  
  21. // Create connection
  22. $dbConn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
  23. $dbConn -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  24.  
  25. return $dbConn;
  26. }
  27.  
  28. // temporary test code
  29. //$dbConn = getDatabaseConnection();
  30.  
  31.  
  32. ?>
Add Comment
Please, Sign In to add comment