In Zend Framework 1.12 Application error: No adapter found for Application_Model_DbTable

I met last time situation in that I run my application with error: No adapter found for Application_Model_DbTable. What’s wrong? – I thought.  And finally I find solution that I perform You.

So, in last post You create database my_animals with only one table animals. You insert in it several animals. Lets create project animals. Choose from Netbeans menu File->New Project.

f09You see New Project window. In it from Categories select PHP and from Projects select PHP Application.

e25Click on Next button.

In Projects Name field write animals and click on Next button.

g2In Projects URL field add on end path word public and click on Next button.

g3In next step select from list of frameworks Zend PHP Web Framework and click on Finish button.

e28In project’s tree You see structure Your application.

g4Create layout. Right click on project animals and choose Zend->Run Command.

g5In Filter field write create layout and click on Run button.

g6In application/layouts/scripts  node open layout.phtml file and paste in it code:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <?php echo $this->layout()->content; ?>    


Right click on project node and choose Zend->Run Command, that create class file for table animals.

g5In Filter field write create db-table and in Parameters field write Animals animals. Animals is class for table and animals is name of table from database.

g8And click on Run button.

In application/models/DbTable node You see Animals.php with Application_Model_DbTable_Animals class.

g9In indexAction method in controller paste this code:

$a = new Application_Model_DbTable_Animals();        
$this->view->animals = $a->fetchAll();

g10In this method You run class of animals table and running its method fetchAll which get all records from this table. This records is giving to view of controller as array with animals name. So go to view index. Open in views/scripts/index index.phtml file and paste in it code:

        <?php foreach ($this->animals as $animal): ?>
           <?php echo $animal['name'] ?><br/>
<?php endforeach; ?>

g11By means of foreach loop You display all records with name of animal.

In public node open .htaccess file and  add on top two lines:

SetEnv APPLICATION_ENV development
DirectoryIndex index.php

g13This allow to view errors on the website if it appear.

Then open application.ini file in application/configs node and paste in it code to connect MySQL database:

resources.db.adapter = "pdo_mysql"
resources.db.params.dbname   = "my_animals"  = "localhost"
resources.db.params.username  = "root"
resources.db.params.password  = "dorota"
resources.db.params.charset  = "utf8"

If You paste this code example after [staging : production] section

g12and run application, You see error:

g14That it repairs, You must cut connecting database code out in application.ini file and paste it before [staging : production] section:

g15Running application You see list of animals from database.


1 thought on “In Zend Framework 1.12 Application error: No adapter found for Application_Model_DbTable

  1. lasertest

    Wow that was unusual. I just wrote an extremely
    long comment but after I clicked submit my comment didn’t show up.
    Grrrr… well I’m not writing all that over again. Anyways, just wanted to say
    fantastic blog!


Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.