I've been working with Doctrine 2 ORM for some time, and there's something I've never quite understood.
What purpose does the Doctrine DBAL (database abstraction layer) serve? PDO itself a database abstraction layer, so why can't the ORM work directly with PDO?
I'm not trying to find a way around using DBAL or anything. I've just never understood why the extra layer is needed, and can't seem to find a clear answer in the documentation.
No, PDO is a "data-access layer", not a "database abstraction layer". Meaning that you can switch databases and still make the same method calls, but PDO will not re-write sql queries to match the selected database or emulate any database functionality.
Per PHP PDO docs:
PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility.
Doctrine2 actually supports some non-PDO databases so that is one reason. It's also useful to look at the source code. The Connection class (for example) has a nice:
public function insert($tableName, array $data)
Which inserts a new record complete with escaping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With