我是个新手,刚开始学习ZendFramework2。当我学习http://framework.zend.com/manual/2.3/en/user-guide/database-and-models.html教程时,我在查找数据库方面遇到了问题。
我发现它可以连接到本地主机数据库,但是找不到任何数据库。
连接错误: SQLSTATEHY000未知数据库“db_vote”
它只能找到数据库"mysql“。但如果我在"mysql“中创建一个新表,则无法找到新表。
另一件奇怪的事情是,我在phpmyadmin中更改了我的根密码,但是在zf2中,如果我更改为新密码,它说访问被拒绝,但它与旧密码一起工作。
似乎zend正在连接到另一个"localhost"?奇怪的想法..。有人能帮我吗?提前谢谢。
Module.php中的代码:
public function getServiceConfig(){
return array(
'factories' => array(
'Album\Model\AlbumTable' => function($sm){
$tableGateway = $sm->get('AlbumTableGateway');
$table = new AlbumTable($tableGateway);
return $table;
},
'AlbumTableGateway' => function($sm){
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Album());
return new TableGateway('album_zend', $dbAdapter, null, $resultSetPrototype);
},
),
);
}global.php:
return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=db_vote; host=localhost',
'driver_options'=> array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' ),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
);local.php:
return array(
'db' => array(
'username' => 'root',
'password' => 'xxxxxxx',
),
);发布于 2015-05-08 08:13:25
问题:
root@localhost
根@%
可以是两个不同的用户。
如果您查看mysql数据库中的user表,您会注意到不止一个根用户。web应用程序的用户可能与通过控制台进行连接的用户不同。
:如何调查它:
检查哪个用户通过控制台(或您使用过的任何其他工具)连接:
SELECT USER();确保您坚持一个用户(例如root@localhost),或者确保web应用程序用户拥有正确的权限:
USE mysql;
SELECT * FROM db;每当您更改特权时,不要忘记刷新它们:
FLUSH PRIVILEGES;https://stackoverflow.com/questions/30103211
复制相似问题