-
Notifications
You must be signed in to change notification settings - Fork 9
Databases
Gaia's database library is a lightweight wrapper around existing php database extensions like mysqli or pdo. You can inject the already instantiated database object into gaia's wrapper object if you so choose and use it in conjunction with Gaia's database tools without changing anything else in your project.
We don't want to push you into using any particular ORM solution. There are a hundred different database abstraction layers written for PHP. And with all of those layers to choose from most often PHP developers choose to write their own on top of the existing php extensions like mysqli or pdo.
When you build your application, you leverage the strengths of your persistence layer. Often ORM solutions try to abstract differences between RDMS solutions away. As a result you get none of the strengths of any of the database platforms. Usually once you pick a database server you stick with it. So why try to create completely portable code for your application?
We just want to get out of the way and let you use what you are comfortable with. There are some useful tools we have written that require database atomicity and transactional integrity. We'd like you to be able to use these tools if you want. And we'd like you to be able to re-use your existing low-level database connections to do the work.
It is a shame to have to open a separate database connection to use gaia's database related libraries when you already have one open for your existing applications. That's why we allow you to inject your database object into our code.
We've written some wrappers for PDO, MySQLi, and CodeIgniter. Writing new wrappers to inject another database layer is as simple as creating a few callbacks. If you need a new adapter send and email to [email protected]. Just pass your connection into our wrappers. The wrappers behave exactly like the core components they wrap, but add a few additional hooks around them:
$db = new \MySQLi($host);
$gaia_db = new Gaia\DB\Callback\Mysqli( $db );
The gaia db object behaves just like the Mysqli object, but has a few enhancements and other hooks in it like the ability to tie into a global nested transaction system. Most of gaia's code has a adapters for the db wrappers you may want to use. If you want support for a new one, let me know. They are trivial to write. Contact [email protected].