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 - using MongoDB to store customer metadata

In this example, we will create a class named Customer. An instance of this class will represent a single row in the customers table of the database. The class will also have methods that store and retrieve the metadata of the customer.

  1. Open a new file in your text editor and put the following code in it:
    <?php require 'mysql.php'; require 'dbconnection.php'; class Customer{ private $_mysql; private $_mongodb; private $_collection; private $_table; private $_id; private $_email; private $_dateOfBirth; private $_createdAt; public function __construct($id = null){ $this->_mysql = getMySQLConnection(); $this->_mongodb = DBConnection::instantiate(); $this->_collection = $this->_mongodb ->getCollection('customer_metadata'); ...

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