-1

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() . "'"
    );
}
4

1 回答 1

2

我远非 PHP 专家,但我有运行同时使用 MongoDB 和 MySQL 的系统的经验。

我建议为您的数据访问对象创建接口,然后为 MySQL 或 Mongo 提供特定的实现。例如:

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

然后你可以有一个读/写 MySQL的实现一个读/写 MongoDB 的实现。

可能不需要 ODM。相反,您将数据加载到对象中,然后对对象执行您需要做的任何事情。

于 2013-03-11T22:51:47.290 回答