Database Abstraction Implementation For Mysql And Mongodb

I’m attempting to work out a simple web application (only two tables… a user table and a single data table). Very basic CRUD functionality required.

However, one of the requirements is to make the app work with either MySQL or MongoDB "interchangeably".

I’m having a tough time, in my mind, visualizing how I could structure this app to make switching between MySQL and MongoDB as simple as changing the database configuration or a setting flag. The data itself doesn’t have to transfer between the two, but the app needs to be able to use either.

Obviously, with the use of the mongo extensions, accessing MongoDB is possible…but the models are different.

Thoughts?

Because Yii ARs doesn’t support changing attribute names and if you’re columns in MySQL are diffent than in MongoDB you’d have to introduce a second layer of models (classes) that will map them to some common names used in your app.

Then, if you use the same names for MySQL and MondoDB models, you can just include another directory with models to switch between them.

Thanks! Not really concerned about the column names being different. It’s more of the fact that I’ll be using Yii ActiveRecord with MySQL and interacting with MongoDB requires an extension. Your reply has me thinking about that set of ‘intermediate’ models though that will be able to use one or the other depending on application settings. I’m not sure how to implement that in Yii exactly, but I’ll look into it further.