1

使用 ZF1,当我创建数据库连接字符串时,它可以正常工作。但是在 ZF2 数据库适配器中似乎 BUG 永远不会起作用,它总是给出以下内容:

错误:

[Fri Nov 02 13:26:25 2012] [error] [client 127.0.0.1] PHP Fatal error:  Class 'Application\\Controller\\Zend\\Db\\Adapter\\Adapter' not found in /var/www/html/org/module/Application/src/Application/Controller/TestController.php on line 17

代码:

<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Db\Adapter\Adapter;
//use Zend\Db\Adapter\Platform\PlatformInterface;
//use Zend\Db\ResultSet\ResultSet;
class TestController extends AbstractActionController {
  public function indexAction() {
    $driverArray = array(
    'driver' => 'Pdo_Mysql',
    'database' => 'web145',
    'username' => 'web145',
    'password' => 'meandmypassword',
    'host'=>'localhost'
    );
    $adapter = new Zend\Db\Adapter\Adapter($driverArray);
    //Zend\Db\Adapter\Adapter::query('SELECT * FROM `sh_operaor`');
    //var_dump ($adapter->query('SELECT * FROM `sh_operaor`'));
    exit;
  }
}
4

1 回答 1

2

由于您已经使用了命名空间 Zend\Db\Adapter\Adapter,您应该这样称呼它:

$adapter = new Adapter($driverArray);

或者您可以从以反斜杠开头的根名称空间调用它

$adapter = new \Zend\Db\Adapter\Adapter($driverArray);
于 2012-11-02T12:38:42.290 回答