使用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;
}
}
答案 0 :(得分:3)
由于您已经使用了Zend \ Db \ Adapter \ Adapter命名空间,因此您应该这样调用它:
$adapter = new Adapter($driverArray);
或者您可以使用反斜杠
从root命名空间开始调用它$adapter = new \Zend\Db\Adapter\Adapter($driverArray);