Guest User

Untitled

a guest
Sep 5th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <?php
  2. /**
  3. * AppFogMongo Class
  4. * Designed for AppFog Platform as a Service (PaaS). Obtains the connection details and esteblishes a connection to the Db. Extends PHPs Mongo Class.
  5. *
  6. * @author Phil Kershaw
  7. */
  8. class AppFogMongo extends Mongo
  9. {
  10. /**
  11. * Contructor
  12. * Captures the Db connection details from the VCAP_SERVICES environment variable and establishes a connection to the Db
  13. *
  14. */
  15. public function __construct()
  16. {
  17. $services_json = json_decode(getenv("VCAP_SERVICES"), true);
  18. $$mongo_config = $services_json["mongodb-1.8"][0]["credentials"];
  19.  
  20. $username = $$mongo_config["username"];
  21. $password = $$mongo_config["password"];
  22. $hostname = $$mongo_config["hostname"];
  23. $port = $$mongo_config["port"];
  24. $db = $$mongo_config["db"];
  25.  
  26. $this->db = parent::__construct("mongodb://${hostname}:${port}", array(
  27. 'username' => $username,
  28. 'password' => $password,
  29. 'db' => $db
  30. ));
  31. }
  32. }
Add Comment
Please, Sign In to add comment