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'); $this->_table = 'customers'; if(isset($id)) { $this->_id = $id; $this->_load(); } } private function _load(){ $query = sprintf("SELECT * FROM %s WHERE id = %d", $this->_table, $this...