Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * AppFogMongo Class
- * Designed for AppFog Platform as a Service (PaaS). Obtains the connection details and esteblishes a connection to the Db. Extends PHPs Mongo Class.
- *
- * @author Phil Kershaw
- */
- class AppFogMongo extends Mongo
- {
- /**
- * Contructor
- * Captures the Db connection details from the VCAP_SERVICES environment variable and establishes a connection to the Db
- *
- */
- public function __construct()
- {
- $services_json = json_decode(getenv("VCAP_SERVICES"), true);
- $$mongo_config = $services_json["mongodb-1.8"][0]["credentials"];
- $username = $$mongo_config["username"];
- $password = $$mongo_config["password"];
- $hostname = $$mongo_config["hostname"];
- $port = $$mongo_config["port"];
- $db = $$mongo_config["db"];
- $this->db = parent::__construct("mongodb://${hostname}:${port}", array(
- 'username' => $username,
- 'password' => $password,
- 'db' => $db
- ));
- }
- }
Add Comment
Please, Sign In to add comment