0
votes

I have following in the configuration of a Zend project

            'db' => array(
                    'driver'         => 'Pdo',
                    'dsn'            => 'mysql:dbname=food;host=localhost',
                    'username' => 'root',
                    'password' => '',
                    'driver_options' => array(
                            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
                    )
            ),
            'service_manager' => array(
                    'factories' => array(
                            'Zend\Db\Adapter\Adapter'
                            => 'Zend\Db\Adapter\AdapterServiceFactory',
                    ),
            ),

I am trying to get DB adapter

($adapter = $adapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');

( $adapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');

in a controller but is always stuck with.

class: "Zend\ServiceManager\Exception\ServiceNotCreatedException" file: " /path/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php" line: 909 message: "An exception was raised while creating "Zend\Db\Adapter\Adapter"; no instance returned"

1
Your code looks okay apart from the unnecessary double $adapter assignment. Are there no other errors above the one you posted?Tim Fountain
Oh, It was a typo, I tried writing code again! it is corrected now.Amit

1 Answers

0
votes

An exception was raised while creating "Zend\Db\Adapter\Adapter"; no instance returned

This could be your problem. The __construct method can throw an InvalidArgumentException(docs).
You should try to create an instance of Zend\Db\Adapter\Adapter on your own and see if an exception is thrown.