docs/en/reference/portability.rst
There are often cases when you need to write an application or library that is portable across multiple different database vendors. The Doctrine ORM is one example of such a library. It is an abstraction layer over all the currently supported vendors (MySQL, Oracle, PostgreSQL, SQLite and Microsoft SQL Server). If you want to use the DBAL to write a portable application or library you have to follow lots of rules to make all the different vendors work the same.
There are many different layers that you need to take care of, here is a quick list:
rtrim().For each point in this list there are different abstraction layers in Doctrine DBAL that you can use to write a portable application.
To handle all the points 1-3 you have to use a special wrapper around the database
connection. The handling and differences to tackle are all taken from the great
PEAR MDB2 library <http://pear.php.net/package/MDB2/redirected>_.
Using the following code block in your initialization will:
rtrim() all strings if necessary.. code-block:: php
<?php
use Doctrine\DBAL\ColumnCase;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Portability\Connection as PortableConnection;
use Doctrine\DBAL\Portability\Middleware as PortableMiddleware;
$configuration = new Configuration();
$configuration->setMiddlewares([
// Other middlewares
//...
new PortableMiddleware(PortableConnection::PORTABILITY_ALL, ColumnCase::LOWER),
]);
This sort of portability handling is pretty expensive because all the result rows and columns have to be looped inside PHP before being returned to you. This is why by default Doctrine ORM does not use this compatibility wrapper but implements another approach to handle assoc-key casing and ignores the other two issues.
Using the database platform you can generate bits of SQL for you, specifically in the area of SQL functions to achieve portability. You should have a look at all the different methods that the platforms allow you to access.
Doctrine ships with lists of keywords for every supported vendor. You
can access a keyword list through the schema manager of the vendor you
are currently using or just instantiating it from the Doctrine\DBAL\Platforms\Keywords
namespace.