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.
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: