Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

103 lines (77 sloc) 2.995 kb

Setting up a database adapter


In most cases, e.g. in your controllers, your database adapter can be fetched directly from the service manager. Some classes however, like Zend\Validator\DbRecordExists isn't aware of the service manager, but still needs an adapter to function.

There are many different ways to provide this functionality to your application. Below are a few examples.

Basic setup

Normally you will setup your database adapter using a factory in the service manager in your configuration. It might look something like this:

The adapter can then be accessed in any ServiceLocatorAware classes.

More information on adapter options can be found in the docs for :ref:`Zend\\Db\\Adapter <zend.db.adapter>`.

Setting a static adapter

In order to utilize this adapter in non-ServiceLocatorAware classes, you can use Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter() to set a static adapter:

The adapter can then later be fetched using Zend\Db\TableGateway\Feature\GlobalAdapterFeature::getStaticAdapter() for use in e.g. Zend\Validator\DbRecordExists:

Jump to Line
Something went wrong with that request. Please try again.