-2

I am using opencart (an opensource framework for e-commerce).

It uses only mysql database as its data source.

However due to the current site traffic, I am sure that we can increase our efficiency by using noSQL (Mongodb). Thats great but the issue is how would I go about and integrate Mongodb to use it with Mysql in unison?

I started looking around and found Mandango (http://mandango.org/) for mapping and have better performance than that of doctrine.

However I am not able to get my head around as to how will I map the data. I looks like that ODM uses objects but when I use my model object in this case, would that not be based on the raw SQL queries.To give you an idea, currently Opencart has models that have raw SQL queries. Below is the example of customer model method.

public function editCustomer($data) {
    $this->db->query(
        "UPDATE " . DB_PREFIX 
        . "customer SET firstname = '" . $this->db->escape($data['firstname']) 
        . "', lastname = '" . $this->db->escape($data['lastname']) 
        . "', email = '" . $this->db->escape($data['email']) 
        . "', telephone = '" . $this->db->escape($data['telephone']) 
        . "', fax = '" . $this->db->escape($data['fax']) 
        . "' WHERE customer_id = '" . (int) $this->customer->getId() . "'"
    );
}
Community
  • 1
  • 1
Asim Zaidi
  • 27,016
  • 49
  • 132
  • 221

1 Answers1

2

I'm far from a PHP expert, but I have experience running systems that use both MongoDB and MySQL.

I would recommend creating interfaces for your data access objects and then having specific implementations for either MySQL or Mongo. For example:

interface iCustomerDAO 
{ 
   public function getCustomer($id);
}
class MySQLCustomerDAO implements iCustomerDAO
{
   public function getCustomer($id) 
   {
      ...
      return $customer;
   }
}

Then you can have an implementation that reads/writes to MySQL and an implementation that reads/writes to MongoDB.

An ODM might not be needed. Instead you load data into objects and then do whatever you need to do with the objects.

ryan1234
  • 7,237
  • 6
  • 25
  • 36