0

Despite several hits on Google I still couldn't find out how to access the db adapter I configured in my global.php in any controller.

I found this:

$db = $this->getParam('bootstrap')->getPluginResource('db')->getDbAdapter();

But it's giving me a ServiceNotFoundException.

Could anybody be so kind to just tell me a quick way to get to the db adapter for making an raw SQL query? (yes, I know that it shouldn't to this but its just temporary)

Thanks!

Ron
  • 22,128
  • 31
  • 108
  • 206

1 Answers1

9

You'd access these kind of things through the ServiceManager. Try the following:

$this->getServiceLocator()->get('Zend\Db\Adapter\Adapter'); 
// replace 'Zend\Db\Adapter\Adapter' with name of adapter if different
Sam
  • 16,435
  • 6
  • 55
  • 89
pjabang
  • 199
  • 1
  • 2