lox / pheasant

A lightweight data mapper designed to take advantage of PHP 5.3+
http://getpheasant.com
MIT License
101 stars 21 forks source link

Replace Mysqli with DBAL? #149

Open lox opened 9 years ago

lox commented 9 years ago

We've done some work to replace the Mysqli parts of Pheasant with Doctrine's DBAL project. Thoughts on whether this is something we'd want to do for 2.0?

bjornpost commented 9 years ago

There were some thoughts on replacing Mysqli with PDO in the past. I'm all in favor of making Pheasant less dependent on MySQL (read: db independent). I'm not familiair with Doctrine's DBAL project, what does it do? And what are the pros/cons versus vanilla PDO?

lox commented 9 years ago

DBAL is a database abstraction layer, where as PDO is just a connection abstraction layer. DBAL will actually rewrite SQL to suit different database engines.

Beyond that DBAL offers a nice connection api that would replace a lot of code in Pheasant, including things like better transaction handling and nice extras like sharding and caching.

bjornpost commented 9 years ago

If we want Pheasant to support more database backends, writing all that code ourselves wouldn't add much value. It just adds a bunch of complexity on our side which we have to test and maintain. I'm all in favor of using a 3rd party library to keep our own code base small. Again, not familiar with the specifics of the Doctrine's DBAL project, but Doctrine seems well tested and has a lot of eyes looking at it.

What are the implications of such a change in terms of performance and Pheasants public API?

lox commented 9 years ago

Hmmm, it depends. I'd say the biggest impact would be that we expose the classname of \Pheasant\Database\Mysqli:Connection in a lot of places.

lox commented 9 years ago

Performance implications would be minimal, and it would have huge security upside in that parameter binding could be moved into DBAL/pdo.

bjornpost commented 9 years ago

I'd say go for it :+1:

Jud commented 9 years ago

I'm for this change :+1: .

After adding in HasManyThrough (https://github.com/judsonco/pheasant/commit/acc46036b2fd4875f9807659b96876d2b590c2ea) relationships and HasOneThrough (https://github.com/judsonco/pheasant/commit/3e0c82b8119b1d2776cfc7ae6094347f7dacede2) there's lots of hackiness around getting the current table alias and it seems like DBAL handles that quite a bit better, and the code could be simplified a good bit.

bjornpost commented 9 years ago

@lox, any progress on this?

bjornpost commented 8 years ago

@lox, can you push this to a separate branch? I have some time to work on this.