1

i've a very specific problem, but i'm a niewbie with zend framework so i don't have idea of how exctly this db adapter works as a configuration, but i've already made a db connection with the default adapter of zend, and it was successful. Now i've to set two different database connections for two different db in the same application. So i've taken my application.ini and i've written the following lines:

 ;connessione al db
 resources.db.adapter = pdo_mssql
 resources.db.params.host = "ip"
 resources.db.params.username = user
 resources.db.params.password = pwd
 resources.db.params.dbname = NAME
 resources.db.isDefaultTableAdapter = true
 resources.db.params.pdoType = dblib

 ;connessione al db1
 resources.db1.adapter = pdo_mssql
 resources.db1.params.host = "ip"
 resources.db1.params.username = user
 resources.db1.params.password = pwd
 resources.db1.params.dbname = NAME
 resources.db1.isDefaultTableAdapter = false
 resources.db1.params.pdoType = dblib

then i went to my action controller and i wrote:

    $db = Zend_Registry::get ( 'db' );
    $result = $db->fetchRow("SELECT [Sell-to Customer No_] FROM dbo.SyncroPlanningTable WHERE id='".$id);
    $rag_soc=$result->{"Sell-to Customer No_"};
    $db1 = Zend_Registry::get ( 'db1' );
    $result1 = $db1->fetchRow("SELECT [No_],[Name],[Address],[City],[Contact],[Name],[Phone] FROM `dbo.SOS$Customer` WHERE No_ = '".$rag_soc."'");

The error i'm getting is the following:

 Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'Unable to resolve plugin "db1";

UPDATE:

My bootstrap.php is:

    $resource = $this->getPluginResource ( "db" );
    $db = $resource->getDbAdapter ();
    $db->setFetchMode ( Zend_Db::FETCH_OBJ );

    Zend_Db_Table_Abstract::setDefaultAdapter ( $db );
    Zend_Registry::set ( "db", $db );

How can i change it? it is not mentioned in the manual page you gave me.

2 Answers 2

2

resources.db refers to Zend_Application_Resource_Db, so "db" here is not a variable name.

You should use Zend_Application_Resource_Multidb to support multiple database connections:

http://framework.zend.com/manual/1.12/en/zend.application.available-resources.html#zend.application.available-resources.multidb

Sign up to request clarification or add additional context in comments.

Comments

1

Your code is expecting the DB adapters to be in the registry, so you need to grab them from the multiDB resource and store them:

$multiDB = $this->getPluginResource('multidb');

Zend_Registry::set('db1', $multiDB->getDb('db1');
Zend_Registry::set('db2', $multiDB->getDb('db2');

also, this line:

Zend_Db_Table_Abstract::setDefaultAdapter ( $db );

can be removed, as you're specifying the default adapter in the application.ini.

1 Comment

Fatal error: Uncaught exception 'Zend_Application_Resource_Exception' with message 'A DB adapter was tried to retrieve, but was not configured' ... but0ve configured the adapter in application.ini... ???????

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.