Skip to content

Instantly share code, notes, and snippets.

@smozgur
Last active July 3, 2016 23:36
Show Gist options
  • Save smozgur/61563f0ceddcade976372ea260ad14b2 to your computer and use it in GitHub Desktop.
Save smozgur/61563f0ceddcade976372ea260ad14b2 to your computer and use it in GitHub Desktop.
ZF3 - Failure with multiple db Adapters and Zend Developer Tools.

This is about Zend Developer Tools and setting up multiple db adapters in the same application. I was having a hard time to make it worked then gave up and uninstalled developer tools since it was affecting my work. I was available today to revisit and I found out how to deal with it.

If you set up multiple database adapters as below to use in your application (global.php) - which is perfectly fine and if you also have zendframework/zend-developer-tools installed, then it would fail with some error saying "Adapter class’ createDriver method expects a "driver" key to be present inside the parameters". So it - zend developer tools - is actually looking for the single "db" configuration instead our new one consist with "adapters" key.

There must be a proper way to solve this out but I couldn’t find anywhere - yet. So I just added a "driver" key into the topmost db config key as shown in the attached global.php file.

Now everything works as I believe developer tools is happy. Just as a note if anybody else has the same problem. And also to find out official way of solving this if any.

<?php
/**
* global.php
*/
return [
'db' => [
'driver' => 'Pdo', // I added this line to make Developer Tools happy, now it works without problem
'adapters' => [
'Application\Db\LocalDb' => [
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=somedb;host=localhost',
'username' => 'someuser',
'password' => 'somepwd',
],
'Application\Db\RemoteDb' => [
'driver' => 'Pdo',
'dsn' => 'odbc:OtherODBCDb',
'username' => 'anotheruser',
'password' => 'anotherpwd',
],
],
],
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment