at 2011-12-30
in Databases
by friebe
(0 comments)
In a recent discussion in the XP Framework's issue tracker, the topic was brought up that the database connectivity layer was preferring the userland MySQL implementation over PHP's builtin-MySQL support. This change occurs in PHP versions using the mysqlnd implementation (default as of PHP 5.3.0) and was causing productive applications to malfunction.
While the change in the XP Framework was made due to the fact that mysqlnd doesn't support older MySQL versions, matching our BC strategy, and there should've been more testing before deploying upgraded versions of both PHP and the XP Framework, it's still undesirable that there's no easy way "back". As a result of the discussion, the database drivers API was made more flexible. Here's an overview of what the pull request consists of:
Providing driver implementations The DriverManager class now no longer hardcodes drivers but leaves this to a so-called DriverImplementationsProvider. Its default implementation, rdbms.DefaultDrivers, knows about all built-in connection implementations and preferences therein. It will be asked to provide driver implementations for a given driver family (e.g. "mysql") in the order they think best matches functionality, performance and conformity / most likely to be registerable (a connection implementation may not be registerable as prerequisites like e.g. ext/sybase_ct may not exist).
Retrieving connections Connections are still retrieved via the getConnection(string $dsn) method. The DSN itself may contain a family and an optional driver specifier attached with a "+" sign.
- getConnection('family') returns any driver implementation for the same family in the order as defined by the SPIs and fails only if no registered connections are available.
- getConnection('family+specifier') returns the driver implementation with the exact driver and will fail if this is not registered.
Registration The register() method is used to make connection driver implementations known to the driver manager.
- register('family', $driver) overwrites the family and forces this driver. This should not be used by vendor implementations that wish to conform to the coexistance model.
- register('family+specifier', $driver) overwrites only the specific driver. Queries via getConnection('family') may or may not yield this driver in future lookups, exact lookups via getConnection('family+specifier') will.
BC To retrieve a connection by a family which was previously supported before this patch, nothing has changed.
Selecting To forcefully select a specific driver for a single connection we can now use getConnection('family+specifier') - in this example here it would be:
$conn= DriverManager::getConnection('mysql+std://user:pass...'); Please note that you should know your environment very well when doing this! If the mysql extension is not available this will raise an exception!
|
Subscribe
You can subscribe to the XP framework's news by using RSS syndication.
CategoriesNews General PHP5 Announcements RFCs Further reading Examples Editorial EASC Experiments Unittests Databases 5.8-SERIES Unicode Language 5.9-SERIES
RelatedFind related articles by a search for «Explicitely».
|