I am a newbie just start learning Zend Framework 2. When I am following the tutorial http://framework.zend.com/manual/2.3/en/user-guide/database-and-models.html, I have a problem with find database.
I found that it can connect to the localhost database, but cannot find any database.
Connect Error: SQLSTATE[HY000] [1049] Unknown database 'db_vote'
It can only find the database "mysql". But cannot find the new table if I create a new table inside "mysql".
The other thing weird is I changed my root password in phpmyadmin, but in zf2, if I change to new password it said access denied, but it works with the old password.
Seems like zend is connecting to the other "localhost"? Weird thoughts... Anyone can help me? Thanks in advance.
Code in 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',
),
);
db_vote
? You should be able to do this with phpmyadmin – Tim Fountain