Zend Framework: Zend_DB Error

Posted by Sergio E. on Stack Overflow See other posts from Stack Overflow or by Sergio E.
Published on 2010-01-25T01:52:57Z Indexed on 2012/09/15 21:39 UTC
Read the original article Hit count: 301

Filed under:
|

I'm trying to learn ZF, but got strange error after 20 minutes :)

Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'Configuration array must have a key for 'dbname' that names the database instance'

What does this error mean? I got DB information in my config file:

resources.db.adapter=pdo_mysql
resources.db.host=localhost
resources.db.username=name
resources.db.password=pass
resources.db.dbname=name

Any suggestions?

EDIT:

This is my model file /app/models/DbTable/Bands.php:

class Model_DbTable_Bands extends Zend_Db_Table_Abstract
{
    protected $_name = 'zend_bands';
}

Index controller action:

public function indexAction()
{
    $albums = new Model_DbTable_Bands();
    $this->view->albums = $albums->fetchAll();
}

EDIT All codes:

bootstrap.php

protected function _initAutoload()
{
    $autoloader = new Zend_Application_Module_Autoloader(array(
        'namespace' => '',
        'basePath'  => dirname(__FILE__),
    ));
    return $autoloader;
}

protected function _initDoctype()
{
    $this->bootstrap('view');
    $view = $this->getResource('view');
    $view->doctype('XHTML1_STRICT');
}

public static function setupDatabase()
{
    $config = self::$registry->configuration;
    $db = Zend_Db::factory($config->db);
    $db->query("SET NAMES 'utf8'"); 
    self::$registry->database = $db;
    Zend_Db_Table::setDefaultAdapter($db);
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
}

IndexController.php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $albums = new Model_DbTable_Bands();
        $this->view->albums = $albums->fetchAll();
    }
}

configs/application.ini, changed database and provided password:

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
db.adapter = PDO_MYSQL
db.params.host = localhost
db.params.username = root
db.params.password = pedro
db.params.dbname = test

models/DbTable/Bands.php

class Model_DbTable_Bands extends Zend_Db_Table_Abstract
{
    protected $_name = 'cakephp_bands';

    public function getAlbum($id) 
    {
        $id = (int)$id;
        $row = $this->fetchRow('id = ' . $id);
        if (!$row) {
            throw new Exception("Count not find row $id");
        }
        return $row->toArray();    
    }
}

© Stack Overflow or respective owner

Related posts about zend-framework

Related posts about zend-db