1

我有一个使用 Zend Framework 构建的网站,由 Windows 10 上的 Wamp32 和 PHP 7 运行,连接到 MySQL 数据库。

我现在正在尝试添加到 DashDB 的连接。

从这里下载了 PECL 文件,将它们安装在 PHP 7 的 ext 目录中,将它们添加到php.ini文件中,我可以在 WAMP 的扩展菜单中看到php_ibm_db2php_pdo_ibm

在我的global.php文件中,我有以下内容:

$database = "BLUDB";
$user = "dashdb_user";
$password = "dashdb_passwd";
$hostname = "dashdb_host";
$port = 50000;

return array(
    'db' => array(
        'driver'         => 'Pdo',
        'dsn'            => 'mysql:dbname=mysql_db;host=localhost',
        'driver_options' => array(
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
        ),
        'adapters'=>array(
            'db2' => array(
                'driver'         => 'IbmDb2',
                'database' => "DRIVER = { IBM DB2 ODBC DRIVER }; DATABASE = $database; HOSTNAME=$hostname; PORT = $port; PROTOCOL = TCPIP ; UID = $user ; PWD = $password;",
            ),
        )
    ),

我还在local.php文件中将凭据添加到 DashDB

return array(
    'db' => array(
        // for primary db adapter that called
        // by $sm->get('Zend\Db\Adapter\Adapter')
        'username' => 'mysql_username',
        'password' => mysql_passwd',

        // to allow other adapter to be called by
        // $sm->get('db1') based on the adapters config.
        'adapters' => array(
            'db2' => array(
                'username' => 'dashdb_user',
                'password' => 'dashdb_passwd',
            ),
        ),
    ),
);

最后在Module.php文件中,我有:

public function onBootstrap(MvcEvent $e)
{
    $eventManager        = $e->getApplication()->getEventManager();
    $moduleRouteListener = new ModuleRouteListener();
    $moduleRouteListener->attach($eventManager);

    $sm = $e->getApplication()->getServiceManager();
    $sm->get('db2');
}

但是当我尝试加载网站时,会出现此错误:

( ! ) Fatal error: Uncaught Zend\Db\Adapter\Exception\RuntimeException: The ibm_db2 extension is required by this driver. in F:\wamp\www\playdon_website\vendor\zendframework\zend-servicemanager\src\ServiceManager.php on line 1130
( ! ) Zend\ServiceManager\Exception\ServiceNotCreatedException: An abstract factory could not create an instance of db2(alias: db2). in F:\wamp\www\playdon_website\vendor\zendframework\zend-servicemanager\src\ServiceManager.php on line 1130
Call Stack
#   Time    Memory  Function    Location
1   0.0303  357304  {main}( )   ...\index.php:0
2   0.5798  867056  Zend\Mvc\Application::init( )   ...\index.php:17
3   3.4846  3664936 Zend\Mvc\Application->bootstrap( )  ...\Application.php:281
4   3.8506  4129480 Zend\EventManager\EventManager->triggerEvent( ) ...\Application.php:169
5   3.8506  4129480 Zend\EventManager\EventManager->triggerListeners( ) ...\EventManager.php:251
6   4.3917  4660464 call_user_func:{F:\wamp\www\playdon_website\vendor\zendframework\zend-eventmanager\src\EventManager.php:490} ( )    ...\EventManager.php:490
7   4.3917  4660464 Application\Module->onBootstrap( )  ...\EventManager.php:490
8   4.4072  4670080 Zend\ServiceManager\ServiceManager->get( )  ...\Module.php:33
9   4.4073  4670600 Zend\ServiceManager\ServiceManager->create( )   ...\ServiceManager.php:530
10  4.4073  4670600 Zend\ServiceManager\ServiceManager->doCreate( ) ...\ServiceManager.php:597
11  4.4073  4670600 Zend\ServiceManager\ServiceManager->createFromAbstractFactory( )
4

0 回答 0