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.

You 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.

In 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.

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

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

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

 
 
    Animals
   
 

        

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

In 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.

In 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:

Animals



       
          


By 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

This 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"
resources.db.params.host  = "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

and 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:

Running application You see list of animals from database.