O'Reilly logo

PHP and MongoDB Web Development by Rubayeet Islam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - building the SessionManager class

Now that we have covered enough of the basics, it is time that we finally get into coding the SessionManager class.

  1. Create a new file named dbconnection.php. Add the following code to that file:
    <?php class DBConnection { const HOST = 'localhost'; const PORT = 27017; const DBNAME = 'myblogsite'; private static $instance; public $connection; public $database; private function __construct() { $connectionString = sprintf('mongodb://%s:%d', DBConnection::HOST, DBConnection::PORT); try { $this->connection = new Mongo($connectionString); $this->database = $this->connection-> selectDB(DBConnection::DBNAME); } catch (MongoConnectionException $e) { throw $e; } } static public function instantiate() { if ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required