简体   繁体   中英

Zend DB Adapter and Service manager

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"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM